2012-11-08 115 views
0

我想夸大alertdialog中的自定义布局。我明白了,但宽度扩展为fill_parent。我已经尝试在xml文件中放置wrap_content或自定义大小(示例200dp),并且它已经fill_parent。自定义高度和宽度在自定义充气alertdialog布局android

我想把自己的高度和宽度,像(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();` 

回答

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 android:name="/*your activity name*/" 
    android:theme="@android:style/Theme.Dialog" 
     android:configChanges="orientation|keyboardHidden" /> 
+0

您好,感谢您的快速回答。我试过alertdialog扩展对话框,但对话框和这一行有错误,对话框()没有定义。我尝试使用Theme.Dialog解决方案,并且活动适应了我的xml大小,这很好,但是这有一个我不想要的标题。所以我已经搜索并在调用super.onCreate之后的活动中放入了:“requestWindowFeature(Window.FEATURE_NO_TITLE);”它工作正常!只是我在寻找!我很开心,谢谢你! – imtheuser

0

您可以创建的LinearLayout比增加空间,或只是查看调整高度你需要再次

相关问题