0

I have implemented a Custom Dialog with Relative layout as Parent.. The issue is that the layout height goes match_parent size even i use wrap_content on Relative Layout...................................................................................................................................

<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"
    />

This is the java code

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

Does Anyone have the answer

Say
  • 31
  • 6

3 Answers3

0

Try using 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();
Nikhil Sawant
  • 103
  • 10
0

Replace your TextView with this

<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"
/>
0

Use Linear Layout as a parent layout instead of RelativeLayout

SahdevRajput74
  • 754
  • 7
  • 18