自定义对话框布局问题

时间:2017-11-17 10:00:54

标签: android dialog relativelayout

我已经实现了一个自定义对话框,其相对布局为Parent ..问题是布局高度是match_parent大小,即使我在相对布局上使用wrap_content ................. .................................................. .................................................. ..............

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<LinearLayout
    android:id="@+id/layoutPopup"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">


    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="2dp"
        android:text="Standered Delvery"
        android:textAlignment="center"
        android:textColor="@color/black"
        android:textSize="18dp"
        />


    <TextView
        android:id="@+id/item_count_popup"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="6 Items"
        android:textAlignment="center" />
    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:background="@color/bg_ash"
        >
    </View>
    <ListView
        android:id="@+id/listview_popup"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="12dp">

    </ListView>
</LinearLayout>
<TextView
    android:id="@+id/popup_dismiss_text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_marginBottom="10dp"
    android:layout_marginRight="10dp"
    android:text="DISMISS"
    android:textColor="@color/orange"
    />

这是java代码

totalCountTxt.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            customDialog = new Dialog(mContext);
            customDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            customDialog.setContentView(R.layout.popup_item_details_delvery_options);
            customDialog.getWindow().setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            ListView listView=(ListView)customDialog.findViewById(R.id.listview_popup) ;

            TextView count=(TextView)customDialog.findViewById(R.id.item_count_popup);
            count.setText(String.valueOf(arrayListCartModel.get(0).getItemCount())+" Items");

            PopupDelveryOptionsAdapter adapter=new PopupDelveryOptionsAdapter(mContext,arrayListCartModel);
            listView.setAdapter(adapter);
            customDialog.show();
        }
    });

Screenshot for a reference

有没有人有答案

3 个答案:

答案 0 :(得分:0)

尝试使用AlertBuilder

final AlertDialog.Builder alertDialog = new AlertDialog.Builder(new ContextThemeWrapper(context, style_to_be_use));

        view = inflater.inflate(your_layoutID,null);
        alertDialog.setView(view);
        alertDialog.setTitle("your title");

alertDialog.setPositiveButton("Submit", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                  //function body
           });
 alertDialog.create();
 alertDialog.show();

答案 1 :(得分:0)

  

用此

替换TextView
<TextView
android:id="@+id/popup_dismiss_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
 android:layout_below="@+id/layout_popup"
android:layout_alignParentRight="true"
android:layout_marginBottom="10dp"
android:layout_marginRight="10dp"
android:text="DISMISS"
android:textColor="@color/orange"
/>

答案 2 :(得分:0)

使用线性布局作为父布局而不是RelativeLayout