[英]TextView height as same as RelativeLayout
我有一个RelativeLayout(1),在此Layout中是一个TextView和另一个RelativeLayout(2)。 RelativeLayout(2)具有动态高度,我希望TextView具有与RelativeLayout(2)相同的高度。 XML
可能吗?
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/layout1">
<TextView
android:id="@+id/textView1"
android:layout_width="40dp"
android:layout_height="match_parent"
android:text="Some Text..."/>
<RelativeLayout
android:id="@+id/layout2"
android:layout_width="match_parent"
android:layout_height="wrap_content">
...
</RelativeLayout>
</RelativeLayout>
我尝试了android:layout_height="match_parent"
和android:layout_height="wrap_content"
但不幸的是,它不起作用。
首先将父布局从RelativeLayout
更改为LinearLayout
然后将其orientation attribute
设置为vertical
接下来,将两个值为1的layout_weight
添加到两个子项: TextView and inner RelativeLayout
android:layout_weight="1"
如果以上不是您所期望的,而是关于相对布局高度变化的textview上的动态变化,那么从技术上讲,我认为XML是不可能的。 您将必须编写一些代码来处理更改事件并在必要时更新视图高度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.