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