[英]TextView height as same as RelativeLayout
I've a RelativeLayout (1) and in this Layout is a TextView and another RelativeLayout (2). 我有一个RelativeLayout(1),在此Layout中是一个TextView和另一个RelativeLayout(2)。 The RelativeLayout (2) has a dynamic height and I want the TextView should has the same height as the RelativeLayout (2).
RelativeLayout(2)具有动态高度,我希望TextView具有与RelativeLayout(2)相同的高度。 Is this with
XML
possible? 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>
I tried with android:layout_height="match_parent"
and android:layout_height="wrap_content"
but unfortunately it doesn't work. 我尝试了
android:layout_height="match_parent"
和android:layout_height="wrap_content"
但不幸的是,它不起作用。
First change the parent layout from RelativeLayout
to LinearLayout
then set its orientation attribute
to vertical
首先将父布局从
RelativeLayout
更改为LinearLayout
然后将其orientation attribute
设置为vertical
Next add layout_weight
with the value of 1 to both children: TextView and inner RelativeLayout
接下来,将两个值为1的
layout_weight
添加到两个子项: TextView and inner RelativeLayout
android:layout_weight="1"
If the above is not what you expect but a dynamic change on textview in reference to a change in height of the relative layout, I would say technically that is not possible with XML. 如果以上不是您所期望的,而是关于相对布局高度变化的textview上的动态变化,那么从技术上讲,我认为XML是不可能的。 You would have to write some codes to handle change events and update the view height when necessary.
您将必须编写一些代码来处理更改事件并在必要时更新视图高度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.