自定义inflate alertdialog布局android中的自定义高度和宽度

时间:2012-11-08 13:19:55

标签: android layout height width inflate

我正在尝试在alertdialog中扩展自定义布局。我明白了,但宽度扩展到fill_parent。我已经尝试在xml文件中放置wrap_content或自定义大小(例如200dp),它曾经是fill_parent。

我想放置自己的高度和宽度,如(200dp,150dp),我该​​怎么说呢?

我已阅读并在此网站上尝试了一些解决方案,但我无法解决我的问题,任何人都可以帮助我吗?提前谢谢。

我在这里提供我的java代码

`>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();`

2 个答案:

答案 0 :(得分:1)

如果您想以自己的方式制作高度和宽度,而不是像下面的

那样制作自定义类扩展对话框
public class AlertCustomDialog extends Dialog {

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

}

并致电

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

何时需要

否则你可以定义Activity并将代码放在清单中,如下所示:

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

答案 1 :(得分:1)

你可以创建LinearLayout而不是添加Space或只是View来调整你需要的高度

相关问题