Android让一个元素占据剩余空间
我有一个活动,它有一个根到顶部的元素,另一个元素应该占据剩余的可用空间。第一个元素的内容会随着时间的推移而变化,需要不同的空间量,第二个元素的大小也会随之变化。这是我已经做过的简化版本:Android让一个元素占据剩余空间,android,xml,android-layout,layout,Android,Xml,Android Layout,Layout,我有一个活动,它有一个根到顶部的元素,另一个元素应该占据剩余的可用空间。第一个元素的内容会随着时间的推移而变化,需要不同的空间量,第二个元素的大小也会随之变化。这是我已经做过的简化版本: <android.support.constraint.ConstraintLayout android:layout_width="match_parent" android:layout_height="match_parent" > <TextView
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:id="@+id/textview_A"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
/>
<TextView
android:id="@+id/textview_B"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/textview_A"
app:layout_constraintBottom_toBottomOf="parent"
/>
</android.support.constraint.ConstraintLayout>
按照当前的方式,顶部元素是正确的,但第二个元素不是。它会将其位置调整为顶部元素底部和父元素底部的中间位置,但其高度与其内容相同,而不是所有可用空间。如何实现这一点?将布局权重设置为1
android:layout=“1”设置布局权重=1
android:layout=“1”在发布类似问题之前,请先搜索。 关于此问题的一些以前的答案
将
id/testview\u B的android:layou height
更改为0dp
。类似于
在发布类似问题之前,请先搜索。
关于此问题的一些以前的答案
将id/testview\u B的android:layou height
更改为0dp
。类似于
或者,尝试如下线性布局:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="text" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher" />
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="D" />
</LinearLayout>
或者,尝试以下线性布局:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="text" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher" />
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="D" />
</LinearLayout>