Rajeev Kumar
Rajeev Kumar

Reputation: 4963

Resize Inflated view not working

I am trying to resize the inflated view but not working

I am adding this view to AlertDialog

 LayoutInflater inflater = getActivity().getLayoutInflater();        
    View view = inflater.inflate(R.layout.popup_util, null,false);
    view.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, 200)); //Set params here


 ......

dialog.setView(view);

popup_util

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/setting_password_popup_element"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/colorPrimary"
    android:orientation="vertical">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/txtPopUpTitle"
        android:padding="10dp"
        android:layout_centerHorizontal="true"
        android:textColor="#000000" android:textSize="24dp" android:background="@color/colorAccent"/>
        <TextView  android:padding="10dp" android:layout_width="match_parent" android:layout_below="@+id/txtPopUpTitle" android:id="@+id/txtPopUpMessage" android:layout_height="wrap_content" android:textSize="22dp"/>


    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="horizontal"
        android:gravity="center_horizontal|bottom">

        <Button android:id="@+id/btnPopUpCancel"
            android:layout_width="match_parent" android:layout_height="50dp"
            android:layout_weight="1"
            android:textSize="24dp"
            android:visibility="gone"
            android:layout_centerHorizontal="true"
            android:background="@android:color/transparent"
            android:text="@string/btn_cancel_text" />

        <Button android:id="@+id/btnPopUpOk"
            android:layout_width="match_parent" android:layout_height="50dp"
            android:textColor="@color/colorAccent"
            android:textSize="24dp"
            android:layout_centerHorizontal="true"
            android:text="@string/btn_ok_text"
            android:background="@android:color/transparent"
            android:layout_weight="1"/>
    </LinearLayout>
</RelativeLayout>

But it is not working.. What i m missing ?

Upvotes: 0

Views: 365

Answers (3)

Ahmed Hegazy
Ahmed Hegazy

Reputation: 12605

You can do that by setting the width and height to the window of the dialog itself.

alertDialog.getWindow().setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, 200);

You must do that after showing the dialog using dialog.show()

Upvotes: 0

groot
groot

Reputation: 420

You can use this code its works good in my case

this.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, theSizeIWant));

NOTE: Be sure to use the parent Layout's LayoutParams. Mine is LinearLayout.LayoutParams!

Upvotes: 0

Aunog
Aunog

Reputation: 47

u cane try this code:

View view = inflater.inflate(R.layout.active_slide, this); view.setMinimumWidth(200);

Upvotes: 1

Related Questions