android - 具有重力和权重的 LinearLayout

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

给定的 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/

相关文章:

java - 我在 Android Studio 的谷歌地图中得到零经度和纬度值

android - 如何以编程方式更改android中的铃声?

资源 getString 的 Android IndexOutOfBound 异常

android - 如何使用 Picasso 为 Google Marker 自定义图标创建语音气泡边框?

android - 按钮不显示在 Activity 底部 - android

android - React-native google signin 给出开发者错误

android - 如何在缩放背景图像上放置按钮

android - setText() 不工作

android-layout - 在android中动态创建UI

android - 在android中获取pdf的路径