I have spent some time on this, and I can't get the ScrollView to work on my Android App. I'm testing it in a Android Emulator, since i don't have an Android device with me right now. I know it should be a silly problem, but I can't figure it out!
The XML code:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:tools="http://schemas.android.com/tools"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="generalclasses.MainActivity$PlaceholderFragment" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="@string/signintextview"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="@+id/useridtext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/usertextview"
android:layout_below="@+id/usertextview"
android:layout_marginTop="25dp"
android:ems="10"
android:hint="@string/hintusuario" />
<TextView
android:id="@+id/usertextview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:layout_marginTop="23dp"
android:text="@string/usertextview"
android:textSize="20sp" />
<Button
android:id="@+id/signupherebutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignRight="@+id/signinbutton"
android:text="@string/signupherebutton" />
<TextView
android:id="@+id/passwordtextview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/useridtext"
android:layout_below="@+id/useridtext"
android:layout_marginTop="24dp"
android:text="@string/passwordtextview"
android:textSize="20sp" />
<EditText
android:id="@+id/passwordedittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/passwordtextview"
android:layout_below="@+id/passwordtextview"
android:layout_marginTop="26dp"
android:ems="10"
android:hint="@string/hintsenha"
android:inputType="textPassword" />
<TextView
android:id="@+id/newheretextview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/signupherebutton"
android:layout_alignBottom="@+id/signupherebutton"
android:layout_alignLeft="@+id/signinbutton"
android:layout_marginLeft="30dp"
android:text="@string/newheretextview"
android:textSize="20sp" />
<Button
android:id="@+id/signinbutton"
style="@style/AppBaseTheme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/passwordedittext"
android:layout_below="@+id/passwordedittext"
android:layout_marginTop="27dp"
android:text="@string/signinbutton" />
</RelativeLayout>
</ScrollView>
我认为发生这种情况是因为您将视图放入RelativeLAyout中,并将其放入LinearLayout中,并将方向设置为纵向
The ScrollView
will only scroll if its content is higher than its actual height. If the content can fit inside the height of the ScrollView
, the ScrollView
will never need to actually scroll.
Is your content higher than the height of your ScrollView
?
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="generalclasses.MainActivity$PlaceholderFragment" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="@string/signintextview"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="@+id/useridtext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/usertextview"
android:layout_below="@+id/usertextview"
android:layout_marginTop="25dp"
android:ems="10"
android:hint="@string/hintusuario" />
<TextView
android:id="@+id/usertextview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:layout_marginTop="23dp"
android:text="@string/usertextview"
android:textSize="20sp" />
<Button
android:id="@+id/signupherebutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignRight="@+id/signinbutton"
android:text="@string/signupherebutton" />
<TextView
android:id="@+id/passwordtextview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/useridtext"
android:layout_below="@+id/useridtext"
android:layout_marginTop="24dp"
android:text="@string/passwordtextview"
android:textSize="20sp" />
<EditText
android:id="@+id/passwordedittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/passwordtextview"
android:layout_below="@+id/passwordtextview"
android:layout_marginTop="26dp"
android:ems="10"
android:hint="@string/hintsenha"
android:inputType="textPassword" />
<TextView
android:id="@+id/newheretextview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/signupherebutton"
android:layout_alignBottom="@+id/signupherebutton"
android:layout_alignLeft="@+id/signinbutton"
android:layout_marginLeft="30dp"
android:text="@string/newheretextview"
android:textSize="20sp" />
<Button
android:id="@+id/signinbutton"
style="@style/AppBaseTheme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/passwordedittext"
android:layout_below="@+id/passwordedittext"
android:layout_marginTop="27dp"
android:text="@string/signinbutton" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
Try Like this, Add your code inside Linear layout , it will Scroll till End of the Page.
<RelativeLayout 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">
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
// Your xml Code Put Here
</LinearLayout>
</ScrollView>
</Relativelayout>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.