custom height and width in custom inflate alertdialog layout android

两盒软妹~` 提交于 2020-01-07 02:17:06

问题


i'm trying to inflate a custom layout in an alertdialog. I get it, but width is expanded to fill_parent. I have tried in xml file to put wrap_content or custom size (example 200dp) and it's ever fill_parent.

I want to put my own height and width, like (200dp, 150dp), how can i put this?

I have read and tried some solutions in this web, but i can't solve my problem, can anyone help me? thanks in advance for it.

I give my java code here

`>View ff = getLayoutInflater().inflate(R.layout.customlayout, null);
        >>Button menu = (Button)ff.findViewById(R.id.menu);
        >>
menu.setOnClickListener(new View.OnClickListener() {                                    
            >>
public void onClick(View v) {

>// TODO Auto-generated method stub 

>>gotomenu();
            }
            }); 
        >
AlertDialog dialog = new AlertDialog.Builder(this)


>.setView(ff)

> .create();        

> dialog.show();`

回答1:


if you want to make height and width on your own way than make custom class extend dialog like below

public class AlertCustomDialog extends Dialog {

public AlertCustomDialog(final Context context,  Event e) {
          requestWindowFeature(Window.FEATURE_NO_TITLE);
          setContentView(/*your layout*/);
          setCancelable(true);
 }

}

and call

    new  AlertCustomDialog(context, e).show();

when you need

otherwise you can define Activity and put code in manifest like below:

  <activity android:name="/*your activity name*/"
   android:theme="@android:style/Theme.Dialog"
        android:configChanges="orientation|keyboardHidden" />



回答2:


You can create LinearLayout and than add Space or just View to adjust height what you need



来源:https://stackoverflow.com/questions/13289661/custom-height-and-width-in-custom-inflate-alertdialog-layout-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!