3

I am using a LinearLayout view with a custom dialog ,when I run the code below, weight is not working correctly as the red view takes the green view's weight and verse vise as image below:

enter image description here

but when I use the same layout in another activity , weight goes correctly as the image below :

enter image description here

ConfirmDialog.java

  public class ConfirmDialog extends DialogFragment {

            @Override
            public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
            }

            public Dialog onCreateDialog(Bundle savedInstanceState) {
                Dialog dialog = super.onCreateDialog(savedInstanceState);
                dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                return dialog;
            }

            @Override
            public View onCreateView(LayoutInflater inflater, ViewGroup container,
                    Bundle savedInstanceState) {

                View view = inflater.inflate(R.layout.dialog_confirm, null);

                return view;
            }

        }

dialog_confirm.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:weightSum="7" >

    <View
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="6"
        android:background="#00ff00" />

    <View
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#ff0000" />

</LinearLayout>
canova
  • 3,965
  • 2
  • 22
  • 39
Android Developer
  • 1,039
  • 1
  • 9
  • 33
  • Make it easier for yourself. Set android:weightSum="1" and View's layout weights to the fractions of the width say 0.7 and 0.3. I find it easier to work with it that way. Apart from that you layout file seems to be fine. – zmicer Jul 17 '13 at 08:08
  • One of the weirdest things I ever seen ... – gunar Jul 17 '13 at 08:13
  • may be this is the problem View view = inflater.inflate(R.layout.dialog_confirm, null); – DynamicMind Jul 17 '13 at 08:34
  • @DynamicMind I checked it before , not solved – Android Developer Jul 17 '13 at 08:55
  • Lets replace this line 'View view = inflater.inflate(R.layout.dialog_confirm, null);' with View view = inflater.inflate(R.layout.dialog_confirm, container, false); – Emre Aktürk Jul 04 '14 at 05:41
  • Have been hit by this right now. It seems to be related to the absence of the title bar. If I avoid calling "dialog.requestWindowFeature(Window.FEATURE_NO_TITLE)" things get fine. – athos May 21 '15 at 16:44

0 Answers0