2015-07-17 8 views
0

Я потратил некоторое время на это, и я не могу заставить ScrollView работать в моем приложении для Android. Я тестирую его в Android Emulator, так как у меня сейчас нет Android-устройства. Я знаю, что это должна быть глупая проблема, но я не могу понять это!ScrollView не работает - Android

XML-код:

<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> 
+0

Вы пытались переместить инструменты линии: контекст в вашем scrollView? –

+0

Возможно, вы нажимаете на edittext и пытаетесь прокручивать. Если это так, попробуйте нажать где-нибудь еще в макете и попробуйте прокрутить. У вас есть элементы, которые не видны на экране, но представлены в макете? – SKT

ответ

0

Я думаю, что это происходит, потому что вы ставите свои взгляды внутри RelativeLayout поместить их в LinearLayout и установите orienation вертикальному

+0

Я пробовал, и это не сработало :( –

+0

установить высоту linearlayout на большое количество, например 2000dp, и проверить, работает ли оно –

0

ScrollView только прокручивать, если его содержание выше его фактической высоты. Если содержимое может вписываться в высоту ScrollView, ScrollView никогда не понадобится прокручивать.

Является ли ваш контент выше, чем высота вашего ScrollView?

0
<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> 
0

Попытайтесь добавить этот код внутри Линейный макет, он будет прокручиваться до конца страницы.

<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> 
Смежные вопросы