2017-09-23 6 views
0

J'ai un RelativeLayout à l'intérieur de ScrollView. Mais ScrollView ne défile pas lorsqu'il est en mode parent.ScrollView ne défile pas lorsque ScrollView en tant que mise en page parent

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:fillViewport="true" 
android:layout_height="match_parent" 

> 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <ImageView 
     android:id="@+id/iv_about_background" 
     android:layout_width="match_parent" 
     android:layout_height="150dp" 
     android:src="@drawable/stack" /> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/iv_about_background" 
     android:paddingLeft="10dp" 
     android:paddingRight="10dp" 
     /> 
</RelativeLayout> 
</ScrollView> 

Edit: Je retire rootView.setOnTouchListener de mon fragment et ScrollView fonctionne très bien

+0

Où se termine votre scrollview? –

+1

https://stackoverflow.com/questions/20896963/relativelayout-inside-scrollview-not-working –

+0

@ Harshit Trivedi Manqué cette ligne lors de la copie. question mise à jour – Ameer

Répondre

0

Essayez avec

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:orientation="vertical" 
android:fillViewport="false" 
android:layout_height="match_parent" 

> 

    <LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 

       <ImageView 
        android:id="@+id/iv_about_background" 
        android:layout_width="match_parent" 
        android:layout_height="150dp" 
        android:src="@drawable/stack" /> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_below="@+id/iv_about_background" 
        android:paddingLeft="10dp" 
        android:paddingRight="10dp" 
        /> 
     </RelativeLayout> 

    </LinearLayout> 

</ScrollView> 
+0

J'ai essayé ceci. Mais pas de défilement. – Ameer

+0

@Ameer set RelativeLayout 'android: layout_height =" match_parent "' –

+1

Ma taille de RelativeLayout est match_parent. J'ai essayé ScrollView dans une autre disposition. Cela fonctionne – Ameer

0

Il y a plusieurs choses que vous pouvez faire:

  1. Assurez-vous que votre contenu en hauteur de disposition relative est plus que le parent. Je pense que 150dp et 10dp encore en dessous de la taille des parents.

  2. Modifier la largeur et la hauteur de ScrollView à fill_parent au lieu de match_parent, et font même des choses à la disposition relative.

  3. Ajouter android:scrollbars = "vertical" propriété ScrollView

espérons qu'il a été utile.

+0

J'ai essayé avec un grand texte sur TextView, il ne défile pas – Ameer

0

Essayez cet espoir il vous aidera.

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fillViewport="true"> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <ImageView 
      android:id="@+id/iv_about_background" 
      android:layout_width="match_parent" 
      android:layout_height="150dp" 
      android:src="@drawable/stack" /> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/iv_about_background" 
      android:paddingLeft="10dp" 
      android:paddingRight="10dp" /> 
    </RelativeLayout> 
</LinearLayout> 

2
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:fillViewport="true" 
android:layout_height="match_parent" 
> 

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <ImageView 
     android:id="@+id/iv_about_background" 
     android:layout_width="match_parent" 
     android:layout_height="350dp" 
     android:src="@drawable/stack" /> 



    <TextView 
     android:text="rgergijsojsoierjgoegorijtowjtojrtoihjorjthlbkmoijbrotoojgowijtogirtjhowortgjowjtgjwrtgjowrijgtoiwjt" 
     android:textSize="50sp" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/iv_about_background" 
     android:paddingLeft="10dp" 
     android:paddingRight="10dp" 
     /> 

</RelativeLayout> 

J'ai changé la hauteur de taille de l'image à 350dp et définir la taille du texte à 50SP savoir si le code que vous avez posté des œuvres ou non. Votre code est parfaitement bien, mais soit vous devez ajouter plus de vues à l'intérieur de scrollview ou augmenter la taille de l'image/taille de police de textview (montré dans le code ci-dessus).