[英]Frame layout not adjusting layout weight
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?? 你可以看到框架布局(在右边)没有总是调整重量。第二和第三列是其他的例外。上面列出的布局在列表视图中膨胀,所有这些都是列表行。所以我我在这做错了?
you just change layout_width = 0dp
to both layouts. 你只需将layout_width = 0dp
更改为两个布局。 and it will be done. 它会完成。
simple. 简单。
you can make your layout lighter, try this xml.. 你可以让你的布局更轻,试试这个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, 只需将dimenssion添加到您的字符串文件中,
<dimen name="icon_height_width">50dp</dimen>
:-) :-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.