具有重力和重量的LinearLayout

kad*_*dir 1 android android-layout

在我的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>
Run Code Online (Sandbox Code Playgroud)

给定的LinearLayout包含一个Title,它应该接受80%的布局和一个Date + Time 20%.日期+时间应具有正确的重力.我发布的布局不幸地工作,如果我使用参数权重,结果是反转的.

有没有另一种方法来获得结果而不交换权重?

ble*_*enm 7

使用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>
Run Code Online (Sandbox Code Playgroud)