如何解决如何使layout_weight固定其宽度
如何使它向左对齐?我希望第二列向左对齐。 我使用layout_weight,但是当内容长度不同时,它将更改父视图的宽度
layout.xml
<LinearLayout
...
android:weightSum="1.1">
<FrameLayout
...
android:layout_weight="0.5">
<TextView/>
</FrameLayout>
<FrameLayout
...
android:layout_weight="0.3">
<TextView/>
</FrameLayout>
<FrameLayout
...
android:layout_weight="0.3">
<TextView/>
</FrameLayout>
</LinearLayout>
解决方法
这是我的一个例子:
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Music"
android:textSize="20dp"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="fewwe"
android:textSize="20dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="wfeewf"
android:textSize="20dp"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="DasDAS"
android:textSize="20dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="dASfafFADS"
android:textSize="20dp"/>
</LinearLayout>
</LinearLayout>
这是结果:
您必须始终放置layout_weight=1
并记住layout_width="match_parent"
我希望这个例子可以帮助您解决问题,cya:)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。