Android 具有重力和重量的线性布局
在我的线性布局中,重量与重力的结合使用会使重量的效果发生逆转。布局:Android 具有重力和重量的线性布局,android,android-layout,Android,Android Layout,在我的线性布局中,重量与重力的结合使用会使重量的效果发生逆转。布局: <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="0.2"> <TextView android:id="@+id/feedfragmentTitle" andr
<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包含一个标题,大约占版面的80%,日期+时间占20%。日期+时间应该具有右边的重力。不幸的是,我发布的布局不起作用,如果我使用参数权重,结果是相反的
有没有其他方法可以在不交换权重的情况下获得结果?尝试这样做
<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>
像这样试试
<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>
使用布局权重属性时,需要将适当的高度或宽度设置为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>
使用布局权重属性时,需要将适当的高度或宽度设置为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的行为?我在另一个项目中使用了一个类似的结构,效果很好!但是为什么我的解决方案不起作用呢?是否有任何问题,或者只是Android/LinearLayout的行为?我在另一个项目中使用了类似的结构,效果很好。