![](/img/trans.png)
[英]How do i set text size in a text view programmatically according to the width of a text view.?
[英]How to set view width according to another view's position?
我在Android XML布局中有一个TextView
和一个Button
(在同一行中, TextView
位于最左侧, Button
位于同一行的最右侧),因为TextView
的文本是动态的,因此对于某些初始文本,其宽度应为最小可见。 随着设备宽度的变化, TextView
的最小宽度一直都不好看。
例如,如果设备的宽度变大,则分配给TextView
的最小宽度将看起来很糟糕,因为它不会占用屏幕上的更多可用空间。
所以我要做的是根据屏幕最右侧出现的Button
的位置设置TextView
的最小宽度
如minWidth =“离开此dp”表单按钮。
我希望您能很好地理解它,然后再问我更多有关它的信息。 寻求使用的属性。
使用水平方向的LinearLayout
将TextView
和Button
放在LinearLayout
。 将该TextView
权重设置为1
,并将width设置为0dp
并使用wrap_content
作为Buttn的宽度
程式码片段
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"/>
</LinearLayout>
将button和textview放在linearlayout内,并根据需要设置textview和button的权重。 它将根据设备屏幕尺寸设置布局视图。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.