有人能告诉我为什么这个ScrollView不工作吗?我检查了这个问题的其他答案,但它并没有解决我的问题。它只有一个孩子。它有一个闭合支架。有什么想法吗?提前感谢
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#89abe3"
tools:context=".GardaLoginActivity" >
<RelativeLayout
android:layout_width="match_parent" android:layout_height="match_parent"
android:focusableInTouchMode="true" android:fitsSystemWindows="true"
android:background="#89abe3">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Smart Neighborhood Watch"
android:id="@+id/Logo"
android:textSize="40dp"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:layout_centerHorizontal="true"
android:layout_marginTop="35dp"
android:textColor="#ffdd00"
android:textStyle="bold"/>
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/Logo"
android:layout_centerHorizontal="true"
android:layout_marginTop="17dp" >
<TextView
android:id="@+id/lblGardaEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Email"
android:textColor="#FFFFFF"/>
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/linearLayout1"
android:layout_centerHorizontal="true"
android:layout_marginTop="17dp">
<EditText
android:id="@+id/txtGardaEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="textEmailAddress"
android:textColor="#FFFFFF"/>
<requestFocus />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/linearLayout2"
android:layout_centerHorizontal="true"
android:layout_marginTop="17dp">
<TextView
android:id="@+id/lblGardaPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="@string/password"
android:textColor="#FFFFFF"/>
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/linearLayout3"
android:layout_centerHorizontal="true"
android:layout_marginTop="17dp">
<EditText
android:id="@+id/txtGardaPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColorHint="#cccccc"
android:hint="Minimum 7 characters"
android:inputType="textPassword"
android:textColor="#FFFFFF" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/linearLayout4"
android:layout_centerHorizontal="true"
android:paddingTop="30dp"
android:gravity="center"
android:weightSum="1">
<Button
android:id="@+id/btnGardaLogin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/login"
android:background="#66c2ff"
android:textColor="#FFFFFF"
android:layout_weight="0.30" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/linearLayout5"
android:layout_centerHorizontal="true"
android:paddingTop="10dp"
android:gravity="center"
>
<TextView
android:id="@+id/textViewGardaRegister"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Not a member? Register"
android:paddingTop="10dp"
android:textColor="#FFFFFF" />
</LinearLayout>
</RelativeLayout>
</ScrollView>
很抱歉我是作为awnser写的,因为我不能对问题发表评论。如果你的布局比屏幕大,滚动视图就会起作用。
还有一件事ScrollView's
高度wrap_content
的子布局
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#89abe3"
tools:context=".GardaLoginActivity" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="true"
android:fitsSystemWindows="true"
android:background="#89abe3">
//Your Code
</RelativeLayout>
</ScrollView>
只需将孩子的相对布局更改为
<RelativeLayout
android:layout_width="match_parent" android:layout_height="match_parent"
android:focusableInTouchMode="true"
android:background="#89abe3">
由于相对布局CCD_ 3属性使用整个屏幕,因此ScrollView没有滚动的空间。
重要提示:
根据Android指南,Android:layout_height属性第一个(也是唯一一个)ScrollView子项应该始终是"包装_内容"。如果您使用match_parent ,您将收到Lint警告
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
>
使用此代码:
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#89abe3"
tools:context=".GardaLoginActivity" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#89abe3"
android:fitsSystemWindows="true"
android:focusableInTouchMode="true" >
<TextView
android:id="@+id/Logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal"
android:layout_marginTop="35dp"
android:gravity="center"
android:text="Smart Neighborhood Watch"
android:textColor="#ffdd00"
android:textSize="40dp"
android:textStyle="bold" />
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/Logo"
android:layout_centerHorizontal="true"
android:layout_marginTop="17dp" >
<TextView
android:id="@+id/lblGardaEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Email"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FFFFFF" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/linearLayout1"
android:layout_centerHorizontal="true"
android:layout_marginTop="17dp" >
<EditText
android:id="@+id/txtGardaEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="textEmailAddress"
android:textColor="#FFFFFF" />
<requestFocus />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/linearLayout2"
android:layout_centerHorizontal="true"
android:layout_marginTop="17dp" >
<TextView
android:id="@+id/lblGardaPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FFFFFF" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/linearLayout3"
android:layout_centerHorizontal="true"
android:layout_marginTop="17dp" >
<EditText
android:id="@+id/txtGardaPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Minimum 7 characters"
android:inputType="textPassword"
android:textColor="#FFFFFF"
android:textColorHint="#cccccc" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/linearLayout4"
android:layout_centerHorizontal="true"
android:gravity="center"
android:paddingTop="30dp"
android:weightSum="1" >
<Button
android:id="@+id/btnGardaLogin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.30"
android:background="#66c2ff"
android:textColor="#FFFFFF" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/linearLayout5"
android:layout_centerHorizontal="true"
android:gravity="center"
android:paddingTop="10dp" >
<TextView
android:id="@+id/textViewGardaRegister"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:text="Not a member? Register"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FFFFFF" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/linearLayout6"
android:layout_centerHorizontal="true"
android:layout_marginTop="17dp" >
<EditText
android:id="@+id/edt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Minimum 7 characters"
android:inputType="textPassword"
android:textColor="#FFFFFF"
android:textColorHint="#cccccc" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout8"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/linearLayout7"
android:layout_centerHorizontal="true"
android:layout_marginTop="17dp" >
<EditText
android:id="@+id/edt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Minimum 7 characters"
android:inputType="textPassword"
android:textColor="#FFFFFF"
android:textColorHint="#cccccc" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout9"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/linearLayout8"
android:layout_centerHorizontal="true"
android:layout_marginTop="17dp" >
<EditText
android:id="@+id/edt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Minimum 7 characters"
android:inputType="textPassword"
android:textColor="#FFFFFF"
android:textColorHint="#cccccc" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/linearLayout9"
android:layout_centerHorizontal="true"
android:layout_marginTop="17dp" >
<EditText
android:id="@+id/edt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Minimum 7 characters"
android:inputType="textPassword"
android:textColor="#FFFFFF"
android:textColorHint="#cccccc" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout11"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/linearLayout10"
android:layout_centerHorizontal="true"
android:layout_marginTop="17dp" >
<EditText
android:id="@+id/edt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Minimum 7 characters"
android:inputType="textPassword"
android:textColor="#FFFFFF"
android:textColorHint="#cccccc" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout12"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/linearLayout11"
android:layout_centerHorizontal="true"
android:layout_marginTop="17dp" >
<EditText
android:id="@+id/edt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Minimum 7 characters"
android:inputType="textPassword"
android:textColor="#FFFFFF"
android:textColorHint="#cccccc" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout13"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/linearLayout12"
android:layout_centerHorizontal="true"
android:layout_marginTop="17dp" >
<EditText
android:id="@+id/edt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Minimum 7 characters"
android:inputType="textPassword"
android:textColor="#FFFFFF"
android:textColorHint="#cccccc" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout14"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/linearLayout13"
android:layout_centerHorizontal="true"
android:layout_marginTop="17dp" >
<EditText
android:id="@+id/edt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Minimum 7 characters"
android:inputType="textPassword"
android:textColor="#FFFFFF"
android:textColorHint="#cccccc" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout15"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/linearLayout14"
android:layout_centerHorizontal="true"
android:layout_marginTop="17dp" >
<EditText
android:id="@+id/edt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Minimum 7 characters"
android:inputType="textPassword"
android:textColor="#FFFFFF"
android:textColorHint="#cccccc" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout16"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/linearLayout15"
android:layout_centerHorizontal="true"
android:layout_marginTop="17dp" >
<EditText
android:id="@+id/edt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Minimum 7 characters"
android:inputType="textPassword"
android:textColor="#FFFFFF"
android:textColorHint="#cccccc" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout17"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/linearLayout16"
android:layout_centerHorizontal="true"
android:layout_marginTop="17dp" >
<EditText
android:id="@+id/edt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="Minimum 7 characters"
android:inputType="textPassword"
android:textColor="#FFFFFF"
/>
</LinearLayout>
</RelativeLayout>
</ScrollView>
我已经检查了您的代码。即使使用卷轴,它也能完美工作。你还有其他疑问吗?