框架布局未调整布局权重 [英] Frame layout not adjusting layout weight

查看:100
本文介绍了框架布局未调整布局权重的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是代码:

<?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.

问题:

如您所见,框架布局(右侧)并非总是调整重量.第二列和第三列是其他列的例外.上面发布的布局在列表视图中被夸大,它们都是列表行.所以我在这里做错了什么?

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??

推荐答案

您只需将layout_width = 0dp更改为两种布局即可.这样就可以了.

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

简单.

您可以使布局更轻松,请尝试使用此xml.

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>

:-)

这篇关于框架布局未调整布局权重的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆