在我的 LinearLayout 中,权重与重力的结合使用会导致反转权重的影响。布局:
<LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_weight="0.2">
<TextView android:id="@+id/feedfragmentTitle" android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_weight="8"/>
<TextView android:id="@+id/feedfragmentDate" android:layout_height="wrap_content" android:gravity="right" android:layout_width="fill_parent" android:layout_weight="2"/>
</LinearLayout>
给定的 LinearLayout 包含一个 Title,它应该大约占 Layout 的 80%,Date+Time 占 20%。 Date+Time 应该有合适的 Gravity。不幸的是,我发布的布局不起作用,如果我使用参数重量,结果是相反的。
有没有其他方法可以在不交换权重的情况下获得结果?
最佳答案
当你使用layout_weight属性时你需要将合适的高度或宽度设置为0dip
试试这个
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:id="@+id/feedfragmentTitle"
android:layout_height="wrap_content" android:layout_width="0dip"
android:layout_weight="8" android:text="sdfdfsfsd"/>
<TextView android:text="aass" android:id="@+id/feedfragmentDate"
android:layout_height="wrap_content"
android:gravity="right" android:layout_width="0dip"
android:layout_weight="2"/>
</LinearLayout>
关于android - 具有重力和权重的 LinearLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7429490/