Здесь встретилось еще одно странное поведение. На этот раз мой диалог сжимается по ширине, несмотря на то, что для всей ширины родительского макета установлено значение fill_parent. Вот изображение ...
Я попытался сделать это мероприятием с темой, установленной как диалог в манифесте. Тем не менее, он ведет себя так же. Однако это становится нормальным, как только я устанавливаю layout_width для первого «Пользовательского соглашения» TextView как 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();
}