-1

我想添加图像到我的相对布局与for循环,但它不工作。 我试图删除for循环,使一个图像更长,滚动视图似乎工作,但是当我尝试添加多个图像的相对layou它添加它,但我不能滚动通过它们。 这意味着我可以看到有5张图片,但我只能看到它的上半部分,无法滚动查看下半部分。ScrollView不滚动在android

这是我用于活动的xml。

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

这里是我用来添加图像

 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; 

     } 

回答

0

我不认为你必须把滚动型的LinearLayout下的活动,因为滚动型默认为LinearLayout中。尝试删除LinearLayout。