开发者

LinearLayout with gravity and weights

In my LinearLayout the use of weight in Combination with Gravity causes to reverse the effect of weight. The Layout:

<LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content"
    android:layout_weight="0.2">
    <T开发者_高级运维extView 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>

The given LinearLayout contains a Title, which should appromately take 80% of the Layout and an Date+Time with 20%. The Date+Time should have the Gravity of right. The layout i posted doesnt work unfortunately and if i play with the parameters weight, the result is the inversed one.

Is there another way to get the Results without swapping the weights ?


When you use the layout_weight property you need to make the appropriate height or width as 0dip

try this

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


Try like this

<LinearLayout 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="wrap_content" android:layout_gravity="left"/>
<TextView android:id="@+id/feedfragmentDate" android:layout_height="wrap_content" android:layout_gravity="right" android:layout_width="wrap_content" />
</LinearLayout>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜