在这里遇到了另一个奇怪的行为。尽管将所有父布局的宽度设置为fill_parent,但我的对话框在宽度方面仍然缩小。以下是图片...
我尝试将其作为具有对话框主题的活动进行设置。但它的行为仍然相同。但是,只要我将第一个TextView“用户协议”的layout_width设置为fill_parent,它就变得正常了。但我不理解这种行为,因为它不应该依赖于TextView的宽度来确定自己的宽度。请告诉我是否有其他有效的方法来处理这些类型的情况。我的布局代码如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@layout/gradientback"
android:orientation="vertical" >
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="User Agreement"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#B80303" />
<View
android:layout_width="fill_parent"
android:layout_height="3dip"
android:background="?android:attr/listDivider" >
</View>
<LinearLayout
android:id="@+id/linearLayout4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<CheckBox
android:id="@+id/checkBoxForTermsId"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#7B4302"
android:text="I Agree The Terms & Conditions" >
</CheckBox>
这不是整个布局的代码,因为我认为它不是必需的...
显示对话框的代码如下:
private void showAgreementBox() {
// TODO Auto-generated method stub
final Dialog dialog = new Dialog(Launcher.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.useragreement);
dialog.setTitle("User Agreement");
dialog.setCancelable(false);
final TextView userAg = (TextView) dialog.findViewById(R.id.textViewOfUserAg);
final CheckBox checkUserAg = (CheckBox) dialog.findViewById(R.id.checkBoxForTermsId);
final Button continueB = (Button) dialog.findViewById(R.id.continueB);
checkUserAg.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (checkUserAg.isChecked() == true) {
continueB.setEnabled(true);
} else {
continueB.setEnabled(false);
}
}
});
continueB.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
dialog.dismiss();
//checkForTrialPeriod(isUserRegisterd);
}
});
Button cancelB = (Button) dialog.findViewById(R.id.cancelB);
cancelB.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
finish();
}
});
dialog.show();
}