水平相关视图的Android线性布局

i86rm4rw  于 2023-03-06  发布在  Android
关注(0)|答案(2)|浏览(138)

我在下面定义了一个布局,它呈现了两个视图-view 1和view 2。对于较小的屏幕尺寸,view 2是扭曲的。
问题-视图2需要出现在右侧,视图1将容纳左侧剩余的任何空间。视图2在尺寸方面非常恒定,可绘制性定义良好。
我该怎么做呢?先谢了。

<LinearLayout
          android:orientation="horizontal"
          android:layout_width="match_parent"
          android:layout_height="wrap_content">

            <TextView
              android:id="@+id/view1"
              android:layout_height="wrap_content"
              android:layout_width="wrap_content"
              android:maxLines="1"
              android:ellipsize="end"
              android:textSize="9pt"
              android:layout_weight = "0"
              android:maxWidth="260dp"
              android:minWidth="260dp"/>

            <TextView
              android:id="@+id/view2"
              android:textStyle="bold"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_gravity="end"
              android:paddingStart="10dp"
              android:paddingEnd="10dp"
              android:background="@drawable/some_drawable"/>
</LinearLayout>

我尝试了layout_width,但无法达到我想要的效果。我是android新手,任何指针也会很有帮助。

bhmjp9jg

bhmjp9jg1#

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <TextView
        android:id="@+id/view1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="7"
        tools:text="view1" />

    <TextView
        android:id="@+id/view2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="3"
        tools:text="view2" />
</LinearLayout>

使用
机器人:布局权重="”
视图1使用**70%的屏幕(android:布局权重=“7”)
view2使用
30%**的屏幕(android:布局权重=“3”)

e4eetjau

e4eetjau2#

对于视图2保留

android:layout_width="wrap_content"
android:layout_height="wrap_content"

并为视图1设置以下内容:

android:layout_width="0dp"
android:layout_weight="1"

这将使视图1在剩余宽度上扩展

相关问题