Frame layout does not adjust the weight of the layout

Here is the code:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginRight="5dp"
    android:layout_marginLeft="5dp"
   >

    <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="1">

    <RelativeLayout
        android:id="@+id/rlengword" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#CCFFFFFF"
        android:layout_weight=".5">
        <TextView
            android:id="@+id/tvengword" 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_centerHorizontal="true"
            android:text="Disrupted"
            android:textColor="#000000"
            android:textSize="16sp"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:paddingTop="20dp"
            android:paddingBottom="20dp"/>

    </RelativeLayout>
    <FrameLayout
        android:id="@+id/rlarabicword" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#CC4b9bcb"        
        android:layout_gravity="center_vertical"

        android:layout_weight=".5">
        <TextView
            android:id="@+id/tvarabicword" 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"      
            android:text="Disrupted"
            android:textColor="#FFFFFF"
            android:textSize="16sp"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:paddingTop="20dp"
            android:paddingBottom="20dp"
           />

        <LinearLayout 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_gravity="right">

        <ImageView 
            android:id="@+id/favicon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingTop="5dp"
            android:paddingRight="4dp"
            android:src="@drawable/star_icon"/>

        <ImageView 
           android:id="@+id/failedicon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingTop="7dp"
            android:paddingRight="4dp"
            android:paddingBottom="4dp"
            android:src="@drawable/exclamation_icon"/>
        </LinearLayout>

    </FrameLayout>
</LinearLayout>
</RelativeLayout>

      

As you can see, I am trying to wrap the frame layout and relative layout in a linear layout, distributing equal weights across them.

Problem:

enter image description here

As you can see the frame layout (right) without adjusting the weight always. The second and third columns are exceptions to the others. The layout posted above is overstated in the list, and they are all lines of the list. So what am I doing wrong here?

+3


source to share


1 answer


you just change layout_width = 0dp

to both layouts. and it will be done.

just.

you can make your layout easier, try this xml ..

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

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:orientation="horizontal"
        android:weightSum="2" >

        <RelativeLayout
            android:id="@+id/rlengword"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#CCFFFFFF" >

            <TextView
                android:id="@+id/tvengword"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:text="Disrupted"
                android:textColor="#000000"
                android:textSize="16sp" />
        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/rlarabicword"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_weight="1"
            android:background="#CC4b9bcb" >

            <TextView
                android:id="@+id/tvarabicword"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:layout_marginRight="@dimen/icon_height_width"
                android:text="Disrupted"
                android:textColor="#FFFFFF"
                android:textSize="16sp" />

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:orientation="vertical" >

                <ImageView
                    android:id="@+id/favicon"
                    android:layout_width="@dimen/icon_height_width"
                    android:layout_height="@dimen/icon_height_width"
                    android:src="@drawable/ic_launcher" />

                <ImageView
                    android:id="@+id/failedicon"
                    android:layout_width="@dimen/icon_height_width"
                    android:layout_height="@dimen/icon_height_width"
                    android:src="@drawable/ic_launcher" />
            </LinearLayout>
        </RelativeLayout>
    </LinearLayout>

</RelativeLayout>

      



just add the size to your string file,

<dimen name="icon_height_width">50dp</dimen>

      

: -)

+2


source







All Articles