【发布时间】:2014-12-22 10:21:40
【问题描述】:
我在 android 应用程序中遇到了自定义对话框问题。
我有一个自定义对话框,里面有一个 ListView。 Dialog 本身是 600dp 宽度,ListView 也是 600dp。
问题是对话框超过了那个宽度值:
这是对话框布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="600dp"
android:layout_height="wrap_content"
android:orientation="vertical">
<ListView
android:id="@+id/promotionListView"
android:layout_width="600dp"
android:layout_height="400dp"
android:scrollbarStyle="insideOverlay"
android:dividerHeight="1dp" />
<LinearLayout
android:layout_width="600dp"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/promotion_dialog_abort"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/annulla"/>
<Button
android:id="@+id/promotion_dialog_apply"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/applica"/>
</LinearLayout>
</LinearLayout>
这是单行的布局:(注意布局的宽度和单视图的总和都是600dp)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="600dp" <-- I tried "wrap_content" and "match_parent" with the same result
android:layout_height="wrap_content">
<CheckBox
android:id="@+id/promotionCheck"
android:layout_width="50dp"
android:layout_height="50dp"
android:gravity="center"
android:layout_gravity="center" />
<TextView
android:id="@+id/promotionText"
android:layout_width="350dp"
android:layout_height="50dp"
android:gravity="center_vertical"
android:layout_gravity="center"
android:textColor="@android:color/white"
android:textSize="@dimen/customerdetail_headertextsize" />
<TextView
android:id="@+id/promotionFactor"
android:layout_width="100dp"
android:layout_height="50dp"
android:gravity="center_vertical|right"
android:layout_gravity="center"
android:textColor="@android:color/white"
android:textSize="@dimen/customerdetail_headertextsize" />
<TextView
android:id="@+id/promotionPrice"
android:layout_width="100dp"
android:layout_height="50dp"
android:gravity="center_vertical|right"
android:layout_gravity="center"
android:textColor="@android:color/white"
android:textSize="@dimen/customerdetail_headertextsize" />
</LinearLayout>
最后是自定义对话框类
public class PromotionDialog extends Dialog {
private boolean authCode;
private Set<OrderDetailDiscount> promotions;
private List<OrderDetailDiscount> selectedPromotions;
private ListView mainListView;
public Response response = Response.CANCEL;
private Button buttonAbort;
private Button buttonAccept;
public PromotionDialog(Context context, boolean authCode, Set<OrderDetailDiscount> promotions) {
super(context);
this.authCode = authCode;
this.promotions = promotions;
selectedPromotions = new ArrayList<>();
setTitle("Promozioni");
setContentView(R.layout.isfa_promotiondialog);
buttonAbort = (Button) findViewById(R.id.promotion_dialog_abort);
buttonAccept = (Button) findViewById(R.id.promotion_dialog_apply);
}
}
我真的不明白问题出在哪里,我尝试手动调整标题栏的大小但没有成功...我可以尝试什么?
【问题讨论】:
标签: android xml android-layout listview dialog