【问题标题】:ScrollView not scrolling in androidScrollView不在android中滚动
【发布时间】:2014-06-22 20:12:14
【问题描述】:

我正在尝试使用 for 循环将图像添加到我的相对布局中,但它不起作用。 我试图删除 for 循环并使一个图像更长,并且滚动视图似乎可以工作,但是当我尝试将多个图像添加到相对布局时,它会添加它,但我无法滚动它们。 这意味着我可以看到有 5 张图片,但我只能看到上半部分,无法滚动查看下半部分。

这是我用于活动的 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;

        }

【问题讨论】:

    标签: android android-activity imageview android-relativelayout android-scrollview


    【解决方案1】:

    我认为你不必将ScrollView放在LinearLayout下,因为ScrollView默认是LinearLayout。尝试删除 LinearLayout。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-29
      • 2020-01-04
      • 1970-01-01
      相关资源
      最近更新 更多