【问题标题】:custom height and width in custom inflate alertdialog layout android自定义膨胀警报对话框布局android中的自定义高度和宽度
【发布时间】:2012-10-28 16:27:59
【问题描述】:

我正在尝试在警报对话框中添加自定义布局。我明白了,但是宽度扩展到了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();`

【问题讨论】:

    标签: android layout height width inflate


    【解决方案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" />
    

    【讨论】:

    • 您好,再次感谢您的快速答复。我尝试了 alertdialog extends dialog 但对话框和此行有错误,对话框()未定义。我尝试了 Theme.Dialog 解决方案,并且活动适应了我的 xml 大小,这很棒,但这有一个我不想要的标题。所以我在调用 super.onCreate 后搜索并在活动中输入:“requestWindowFeature(Window.FEATURE_NO_TITLE);”它工作正常!只是我在找!!!我很高兴,谢谢!
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-24
      • 1970-01-01
      • 2015-04-13
      相关资源
      最近更新 更多