请问线性布局中,水平放置有2个文本框,线性布局的宽度不确定,取决于屏幕大小,如果希望两个文本框等大,即两个都是 layout_weight =1,并且这2个文本框最大都不超过50dp,但是如果设置了两个都是 layout_weight =1,maxWidth就可能会失效吧? 请问这个怎么实现比较稳妥? 假定不能将这2个文本框放置于一个100dp的线性布局中。就是其必须置于长度不确定的一个线性布局中,不能再嵌套使用线性布局。
3条回答 默认 最新
关注<?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>这样写不能满足需求吗?
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报