Android 如何使视图填充剩余空间
所以我的屏幕上有两个“部分”。我有顶部是滚动视图,底部是随机文本。底部的随机文本总是在改变大小,所以有时需要40dp,有时需要20dp,等等 我的问题是,是否有一种方法可以使底部部分动态(不丢失文本),使顶部滚动视图适应新的大小,并根据底部部分使用的部分限制其自身大小以“填充剩余空间” 像这样: 如您所见,滚动视图只会填充剩余的可用空间 我正在寻找一个只使用XML的解决方案Android 如何使视图填充剩余空间,android,xml,Android,Xml,所以我的屏幕上有两个“部分”。我有顶部是滚动视图,底部是随机文本。底部的随机文本总是在改变大小,所以有时需要40dp,有时需要20dp,等等 我的问题是,是否有一种方法可以使底部部分动态(不丢失文本),使顶部滚动视图适应新的大小,并根据底部部分使用的部分限制其自身大小以“填充剩余空间” 像这样: 如您所见,滚动视图只会填充剩余的可用空间 我正在寻找一个只使用XML的解决方案 需要帮助 在垂直线性布局中包裹两个视图 位于顶部的视图:height=“0dp”,weight=1 底部的视图:hei
需要帮助 在垂直
线性布局中包裹两个视图
位于顶部的视图:height=“0dp”
,weight=1
底部的视图:height=“wrap\u content”
您可以试试这个
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/bottomTextView">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="500dp"
android:background="@android:color/holo_red_dark"
android:text="Test" />
</LinearLayout>
</ScrollView>
<TextView
android:id="@+id/bottomTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@android:color/darker_gray"/>
或
非常感谢您!很好的解释
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="500dp"
android:background="@android:color/holo_red_dark"
android:text="Test" />
</LinearLayout>
</ScrollView>
<TextView
android:id="@+id/bottomTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/darker_gray"/>