【发布时间】:2012-08-27 10:38:20
【问题描述】:
我正在使用我作为对话框提示的 XML 布局。 XML 布局的设计格式良好,具有足够的所需高度和宽度.. 但是当我将它作为对话框打开时,它的宽度会受到干扰,那么如何通过编码设置对话框的高度和宽度。
我什至之前提到过这个STACK OVERFLOW QUESTION
代码如下:
// Layout Inflater Code..
editDialog = new Dialog(this);
layoutEdit = LayoutInflater.from(this).inflate(R.layout.createlayout, null);
//layoutEdit.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));
editDialog.setContentView(layoutEdit);
// Called the Dialogbox to inflate
updateButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
editDialog.show();
}
});
// XML 文件代码:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/bd"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:freezesText="false"
android:text="Enter Name"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/whtie"
android:typeface="monospace" />
<EditText
android:id="@+id/txtname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName" >
</EditText>
</LinearLayout>
</ScrollView>
【问题讨论】:
-
我觉得this link很有用...
-
请张贴打开对话框代码
-
请发布您的
xml和dialog box代码 -
请告诉我们您是如何设置宽度和高度的。我确定你做错了什么,因为这是很容易实现的。发布代码,让我们知道你做得不好。
-
@Shafi 我已经发布了对话框代码
标签: android android-layout android-dialog dialog