onunix 2023-08-17 13:15 采纳率: 77.8%
浏览 11
已结题

线性布局中等大并且不超过50dp的2个文本框

请问线性布局中,水平放置有2个文本框,线性布局的宽度不确定,取决于屏幕大小,如果希望两个文本框等大,即两个都是 layout_weight =1,并且这2个文本框最大都不超过50dp,但是如果设置了两个都是 layout_weight =1,maxWidth就可能会失效吧? 请问这个怎么实现比较稳妥? 假定不能将这2个文本框放置于一个100dp的线性布局中。就是其必须置于长度不确定的一个线性布局中,不能再嵌套使用线性布局。

  • 写回答

3条回答 默认 最新

  • 不会写代码的猴子 优质创作者: 操作系统技术领域 2023-08-17 13:40
    关注
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/frameLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
    
    
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
            
            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="文本框1"
                android:textColor="@color/white"
                android:background="@color/black"/>
    
            <TextView
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="@color/black"
                android:textColor="@color/white"
                android:text="文本框2"
                android:layout_marginStart="10dp"/>
            
            
        </LinearLayout>
    
    </LinearLayout>
    

    这样写不能满足需求吗?

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 2月8日
  • 已采纳回答 1月31日
  • 修改了问题 8月17日
  • 创建了问题 8月17日