我似乎想不出如何有效地使用安卓的layout_weight属性。我正在尝试创建一个有三个文本视图的自定义listView。主要的textView位于左上角,然后我有一个位于右上角的文本视图,然后第三个位于主要textView的下面。我希望主要的和右上角的两个在某个水平轴上,但是我希望主要的textView占据大约70%的宽度,而另一个textView占据剩余的30%。无论我为主textView和右textView分配多大的权重,主textView总是更大,并且将正确的数据textView挤得太细。

我的代码:
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dip"
android:id="@+id/Llayout">
<!-- Title-->
<TextView
android:id="@+id/primaryTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Loading some tadglkj dgjg sadlgkj dgksgj sgj sdgk"
android:textColor="#040404"
android:typeface="sans"
android:textSize="18dip"
android:textStyle="bold"
android:paddingTop="0dp"
android:background="#888"
android:layout_weight="4"/>
<!-- Right Data -->
<TextView
android:id="@+id/rightData"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="10"
android:layout_marginRight="5dip"
android:textSize="12dip"
android:textColor="#B53021"
android:textStyle="bold"
android:background="#bada55"
android:text="1.3 mi"/>
</LinearLayout>
<!-- Secondary title -->
<TextView
android:id="@+id/secondaryTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#343434"
android:textSize="12dip"
android:layout_marginTop="1dip"
android:text="hello this is some other data"/>
发布于 2013-05-14 22:56:02
我需要做几件事。
发布于 2013-05-14 22:39:22
在你想要达到70%的项目上设置layout_weight="30",在你想要达到30%的项目上设置layout_weight="70"。这将有望解决您的问题。
发布于 2013-05-14 22:42:31
你需要在你的容器中定义一个权重和。在您的示例中,如下所示(仅包含所需的相关属性):
<LinearLayout
android:weightSum="1">
<!-- Title-->
<TextView
android:layout_weight=".7"/>
<!-- Right Data -->
<TextView
android:layout_weight=".3"/>
</LinearLayout>https://stackoverflow.com/questions/16546053
复制相似问题