【发布时间】:2020-07-25 11:00:28
【问题描述】:
我有一个具有滚动视图的布局,并包含另一个具有网格视图的布局。问题是当我更改屏幕方向时,根布局(具有滚动视图)没有滚动,但子布局内的网格视图正在实现滚动视图,并且它的项目没有整体显示。我希望根布局始终滚动,网格视图始终显示它的所有项目,而不需要任何滚动。这个怎么办??
内部布局 XML,
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="wrap_content"
android:layout_width="match_parent"
app:cardCornerRadius="@dimen/loginCardRadius"
android:elevation="5dp"
android:layout_gravity="center"
android:layout_marginTop="@dimen/loginViewsMargin"
android:layout_marginBottom="@dimen/loginViewsMargin"
android:background="#ffffff">
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_gravity="center"
android:padding="@dimen/loginViewsMargin">
<ImageView
android:contentDescription="@string/string1"
android:src="@drawable/logo"
android:layout_gravity="center"
android:layout_height="100dp"
android:layout_width="wrap_content"
android:layout_marginTop="@dimen/loginViewsMargin"/>
<GridView
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/grid_view"
android:numColumns="2"/>
</LinearLayout>
</androidx.cardview.widget.CardView>
外部布局 XML,
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_height="match_parent"
android:layout_width="wrap_content">
<ScrollView
android:fillViewport="true"
android:layout_height="match_parent"
android:layout_width="wrap_content">
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content">
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_alignParentTop="true"
android:baselineAligned="true"
android:weightSum="12"
android:background="@drawable/login_shape_bk"
android:orientation="vertical"
android:layout_weight="3">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/ic_login_bk" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:orientation="vertical"
android:layout_marginTop="40dp"
android:layout_marginRight="30dp"
android:layout_marginLeft="30dp">
<TextView
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:textColor="#ffffff"
android:textSize="22sp"
android:textStyle="bold"
android:layout_marginTop="20dp"
android:gravity="center"
android:layout_gravity="center"
android:text="@string/research_work"/>
<include
layout="@layout/layout_advisors"/>
</LinearLayout>
</RelativeLayout>
</ScrollView>
【问题讨论】:
标签: android gridview scrollview