0
     <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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" 
    android:background="@drawable/background">

    <ImageView
        android:id="@+id/iv_bollywood"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="94dp"
        android:src="@drawable/bollywood" />

    <ImageView
        android:id="@+id/iv_hollywood"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/iv_bollywood"
        android:layout_below="@+id/iv_bollywood"
        android:layout_marginTop="14dp"
        android:src="@drawable/hollywood" />

    <ImageView
        android:id="@+id/iv_animated"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/iv_hollywood"
        android:layout_below="@+id/iv_hollywood"
        android:layout_marginTop="14dp"
        android:src="@drawable/animated" />

    <ImageView
        android:id="@+id/iv_hindhi_dub"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
              android:layout_alignLeft="@+id/iv_animated"
        android:layout_below="@+id/iv_animated"
        android:layout_marginTop="14dp"
        android:src="@drawable/hindidub" />

    <ImageView
        android:id="@+id/iv_other"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/iv_hindhi_dub"
        android:layout_below="@+id/iv_hindhi_dub"
        android:layout_marginTop="14dp"
        android:src="@drawable/other" />

        </RelativeLayout>


i am  new in android.i want to  add scroll in my application.

我想在我的图像视图中使用滚动视图。我想在我的应用程序中同时使用水平和垂直滚动视图,我该怎么做。请帮助我并给我任何与我的应用程序相关的代码示例。谢谢...:)

4

3 回答 3

2
    <?xml version="1.0" encoding="utf-8"?>
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/scrollView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        >

        <RelativeLayout
            android:layout_width="318dp"
            android:layout_height="495dp"
             >

<ImageView
        android:id="@+id/iv_bollywood"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="94dp"
        android:src="@drawable/bollywood" />

    <ImageView
        android:id="@+id/iv_hollywood"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/iv_bollywood"
        android:layout_below="@+id/iv_bollywood"
        android:layout_marginTop="14dp"
        android:src="@drawable/hollywood" />

    <ImageView
        android:id="@+id/iv_animated"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/iv_hollywood"
        android:layout_below="@+id/iv_hollywood"
        android:layout_marginTop="14dp"
        android:src="@drawable/animated" />

    <ImageView
        android:id="@+id/iv_hindhi_dub"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
              android:layout_alignLeft="@+id/iv_animated"
        android:layout_below="@+id/iv_animated"
        android:layout_marginTop="14dp"
        android:src="@drawable/hindidub" />

    <ImageView
        android:id="@+id/iv_other"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/iv_hindhi_dub"
        android:layout_below="@+id/iv_hindhi_dub"
        android:layout_marginTop="14dp"
        android:src="@drawable/other" />

        </RelativeLayout>
</ScrollView >

您必须将 ScrollView 作为父级(垂直滚动)...

于 2013-10-30T05:36:51.567 回答
0
<?xml version="1.0" encoding="utf-8"?>
    <ScrollView 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" >

        <HorizontalScrollView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="50dp" >

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/background" >

                <ImageView
                    android:id="@+id/iv_bollywood"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentTop="true"
                    android:layout_centerHorizontal="true"
                    android:layout_marginTop="94dp"
                    android:src="@drawable/bollywood" />

                <ImageView
                    android:id="@+id/iv_hollywood"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignLeft="@+id/iv_bollywood"
                    android:layout_below="@+id/iv_bollywood"
                    android:layout_marginTop="14dp"
                    android:src="@drawable/hollywood" />

                <ImageView
                    android:id="@+id/iv_animated"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignLeft="@+id/iv_hollywood"
                    android:layout_below="@+id/iv_hollywood"
                    android:layout_marginTop="14dp"
                    android:src="@drawable/animated" />

                <ImageView
                    android:id="@+id/iv_hindhi_dub"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignLeft="@+id/iv_animated"
                    android:layout_below="@+id/iv_animated"
                    android:layout_marginTop="14dp"
                    android:src="@drawable/hindidub" />

                <ImageView
                    android:id="@+id/iv_other"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignLeft="@+id/iv_hindhi_dub"
                    android:layout_below="@+id/iv_hindhi_dub"
                    android:layout_marginTop="14dp"
                    android:src="@drawable/other" />
            </RelativeLayout>
        </HorizontalScrollView>

        </ScrollView>

Try this one for Horizontal as well as Vertical scrollview

于 2013-10-30T05:43:24.537 回答
0
<ScrollView 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">

<RelativeLayout 
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background">

<ImageView
    android:id="@+id/iv_bollywood"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="94dp"
    android:src="@drawable/bollywood" />

<ImageView
    android:id="@+id/iv_hollywood"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/iv_bollywood"
    android:layout_below="@+id/iv_bollywood"
    android:layout_marginTop="14dp"
    android:src="@drawable/hollywood" />

<ImageView
    android:id="@+id/iv_animated"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/iv_hollywood"
    android:layout_below="@+id/iv_hollywood"
    android:layout_marginTop="14dp"
    android:src="@drawable/animated" />

<ImageView
    android:id="@+id/iv_hindhi_dub"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
          android:layout_alignLeft="@+id/iv_animated"
    android:layout_below="@+id/iv_animated"
    android:layout_marginTop="14dp"
    android:src="@drawable/hindidub" />

<ImageView
    android:id="@+id/iv_other"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/iv_hindhi_dub"
    android:layout_below="@+id/iv_hindhi_dub"
    android:layout_marginTop="14dp"
    android:src="@drawable/other" />

</RelativeLayout>
</ScrollView>
于 2013-10-30T05:39:11.733 回答