Frame layout not adjusting layout weight

丶灬走出姿态 提交于 2019-12-23 20:21:28

问题


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 a frame layout and a relative layout within a linear layout by distributing equal weights in them.

The problem:

As you can see the frame layout(on the right) not adjusting the weight always.The 2nd and 3rd column is an exception of the others.The layout posted above is inflated in a listview and all of them are list rows.So what I am doing wrong here??


回答1:


you just change layout_width = 0dp to both layouts. and it will be done.

simple.

you can make your layout lighter, 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>

simply add dimenssion to your string file,

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

:-)



来源:https://stackoverflow.com/questions/26837978/frame-layout-not-adjusting-layout-weight

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!