我无法使ScrollView正确滚动。它总是切断底部的内容,就像正常的LinearLayout
一样。
我的代码:
<?xml version="1.0" encoding="utf-8"?>
<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="fill_parent"
android:layout_height="match_parent"
android:fillViewport="true"
tools:context="com.android.dadiperpus.MainActivity">
我把
LinearLayout
放在ScrollView
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/logo_stan"
android:orientation="vertical"
android:weightSum="10">
然后我将RelativeLayout放在LinearLayout中
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal|center_vertical"
android:text="CONTOH BRO"
android:textSize="32sp" />
</RelativeLayout>
在这里我用
Gridlayout
<GridLayout
android:id="@+id/mainGrid"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="8"
android:alignmentMode="alignMargins"
android:columnCount="2"
android:columnOrderPreserved="false"
android:padding="14dp"
android:rowCount="3">
然后我将这段代码放在
GridLayout
<android.support.v7.widget.CardView
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_columnWeight="1"
android:layout_marginBottom="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_rowWeight="1"
app:cardCornerRadius="8dp"
app:cardElevation="8dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_margin="16dp"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="@drawable/logo_stan" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pengantar Kepabeanan"
android:textAlignment="center"
android:textColor="@android:color/black"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
</android.support.v7.widget.CardView>
我已经尝试过将
ScrollView
包装在LinearLayout
中,并且它什么都没有改变。 最佳答案
我将LinearLayout放入ScrollView
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/logo_stan"
android:orientation="vertical"
android:weightSum="10">
此线性布局的高度需要使用
wrap_content
。通过使用match_parent
,您是说要使linearlayout仅与承载它的滚动视图一样高……这意味着它将切断所有“可滚动”的内容。通过使用wrap_content
(或某个大于滚动视图的固定高度),您在linearlayout中将拥有比在一个屏幕上可见的更多内容,然后滚动将按预期进行。关于android - 我的滚动 View 根本不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48172725/