所以我的屏幕上有两个“部分”。我的顶部是 ScrollView,底部是随机文本。底部的随机文本总是会改变大小,所以有时需要 40dp,有时需要 20dp,等等。
我的问题是,有没有办法使底部动态(不丢失文本)并使顶部滚动 View 适应新大小并根据底部部分限制其自身大小以“填充剩余空间”使用?
像这样:
如您所见,滚动 View 仅填充了剩余的可用空间。
我正在寻找仅使用 XML 的解决方案
需要帮忙!
最佳答案
你可以试试这个。
<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"/>
关于android - 如何让View填充剩余空间,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24065813/