【发布时间】:2021-03-09 21:57:06
【问题描述】:
我想构建一个响应式设计的 UI,所以我使用布局权重。看起来 ScrollView 不会用权重滚动。我试过使用没有权重的 ScrollView 并且滚动效果很好。我想知道是否有办法将 ScrollView 与权重一起使用。这是我的代码:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:orientation="vertical"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:background="@color/colorAccent"
android:layout_weight="0.3"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:background="@color/colorPrimary"
android:layout_weight="0.7">
<Button
android:layout_width="match_parent"
android:layout_height="200dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="200dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="200dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="200dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="200dp"
android:text="Last Button"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
任何帮助将不胜感激,谢谢!
【问题讨论】:
标签: java android xml android-studio scrollview