-1

J'essaie d'ajouter des images à ma disposition relative avec une boucle for, mais cela ne fonctionne pas. J'ai essayé d'enlever la boucle for et de faire une image plus longue et la vue de défilement semble fonctionner mais quand j'essaie d'ajouter plus d'une image à la position relative elle l'ajoute mais je ne peux pas les parcourir. Cela signifie que je peux voir qu'il y a 5 images mais je peux seulement voir la moitié supérieure de celui-ci et ne peux pas défiler pour voir la moitié inférieure.ScrollView ne défile pas en android

Voici mon fichier XML que j'utilise pour l'activité.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/ScrollView01" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fillViewport="true" 
    android:scrollbars="none" > 

<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" 
      android:id="@+id/MainRelativeLayout" 
      android:paddingLeft="@dimen/activity_horizontal_margin" 
      android:paddingRight="@dimen/activity_horizontal_margin" 
      android:paddingTop="@dimen/activity_vertical_margin" 
      android:paddingBottom="@dimen/activity_vertical_margin" 
      tools:context="com.tutecentral.tvtimeschedule.app.MainActivity" 
      android:background="#87CABE" 
      android:layout_alignParentTop="true" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true"> 

</RelativeLayout> 
</ScrollView> 
</LinearLayout> 

Et voici l'activité que j'utiliser pour ajouter les images

 int amountOfChannels = 9; 
     int paddingTopOfImage = 0; 

     for(int i = 1; i <= amountOfChannels; i++) { 

      //ImageView Setup 
      ImageView imageView = new ImageView(this); 
      //setting image resource 
      imageView.setImageResource(R.drawable.channel_1); 
      //setting image position 

      imageView.setLayoutParams(new RelativeLayout.LayoutParams(
        RelativeLayout.LayoutParams.MATCH_PARENT, 
        RelativeLayout.LayoutParams.MATCH_PARENT)); 

      imageView.getLayoutParams().height = 400; 
      imageView.getLayoutParams().width = 1000; 

      imageView.setPadding(10, 10, 10, 10); 
      imageView.setBackgroundColor(Color.WHITE); 
      imageView.setScaleType(ImageView.ScaleType.FIT_CENTER); 
      imageView.setY(paddingTopOfImage); 

      //adding view to layout 
      RelativeLayout mainRelativeLayout = (RelativeLayout) findViewById(R.id.MainRelativeLayout); 
      mainRelativeLayout.addView(imageView); 

      paddingTopOfImage = paddingTopOfImage + 450; 

     } 

Répondre

0

Je ne pense pas que vous devez mettre ScrollView sous LinearLayout, parce ScrollView par défaut est LinearLayout. Essayez de supprimer le LinearLayout.

Questions connexes