如何在此布局中添加Scrollview?

时间:2015-01-21 02:18:58

标签: android android-layout scrollview

3 个答案:

答案 0 :(得分:0)

要向scrollview取一个直接子节点并将整个代码放入该布局

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:whatever="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="match_parent" >

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

    <LinearLayout
        android:id="@+id/ll_banner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/common_padding"
        android:layout_marginLeft="@dimen/common_padding"
        android:layout_marginRight="@dimen/common_padding"
        android:layout_marginTop="@dimen/common_padding" >

        <com.amobee.adsdk.AmobeeAdPlaceholder
            android:id="@+id/findCinemaPlaceHolder"
            android:layout_width="match_parent"
            android:layout_height="@dimen/ads_amobee_height" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/ll_map"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_below="@+id/ll_banner"
        android:layout_marginTop="0dp" >

        <FrameLayout
            android:id="@+id/map"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            class="com.google.android.gms.maps.MapFragment" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/ll_banner"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="20dp"
        android:background="@android:color/transparent"
        android:orientation="vertical" >

        <ImageButton
            android:id="@+id/close_map"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/cinemas_close_button_normal"
            android:clickable="true" />
    </LinearLayout>

    <RelativeLayout
        android:id="@+id/rl_location"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_margin="10dp"
        android:background="@android:color/white"
        android:visibility="gone" >

        <com.handmark.pulltorefresh.library.PullToRefreshScrollView
            xmlns:ptr="http://schemas.android.com/apk/res-auto"
            android:id="@+id/pullToRefresh"
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:layout_margin="@dimen/common_padding"
            android:visibility="visible"
            ptr:ptrAnimationStyle="flip"
            ptr:ptrMode="pullFromStart" >

            <LinearLayout
                android:id="@+id/llCinema"
                android:layout_width="fill_parent"
                android:layout_height="match_parent"
                android:layout_margin="10dp"
                android:orientation="vertical" >

                <TextView
                    android:id="@+id/tvNearByCinemas"
                    style="@style/GrayNormalTextView"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:text="NEARBY CINEMAS" />

                <ListView
                    android:id="@+id/list_location"
                    android:layout_width="fill_parent"
                    android:layout_height="match_parent"
                    android:visibility="gone" />

                <LinearLayout
                    android:id="@+id/lLCinemaList"
                    android:layout_width="fill_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical" >
                </LinearLayout>

                <ProgressBar
                    android:id="@+id/pbLoadMoreData"
                    style="?android:attr/progressBarStyle"
                    android:layout_width="30dp"
                    android:layout_height="30dp"
                    android:layout_gravity="center"
                    android:layout_marginBottom="@dimen/common_padding"
                    android:visibility="gone" />
            </LinearLayout>
        </com.handmark.pulltorefresh.library.PullToRefreshScrollView>

        <TextView
            android:id="@+id/tv_msg"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:layout_marginTop="20dp" />
    </RelativeLayout>
</RelativeLayout>

答案 1 :(得分:0)

将你的代码放在ScrollView中,这就像Sandeep的答案一样非常简单。

答案 2 :(得分:0)

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

<RelativeLayout 
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:whatever="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/gray_bg" >

    <LinearLayout
        android:id="@+id/ll_banner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
        android:layout_marginBottom="@dimen/common_padding"
        android:layout_marginLeft="@dimen/common_padding"
        android:layout_marginRight="@dimen/common_padding"
        android:layout_marginTop="@dimen/common_padding" >

        <!--
        <ImageView android:id="@+id/img_top_banner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/cinemas_location_banner"
        />
        -->

        <com.amobee.adsdk.AmobeeAdPlaceholder
            android:id="@+id/findCinemaPlaceHolder"
            android:layout_width="match_parent"
            android:layout_height="@dimen/ads_amobee_height" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/ll_map"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_below="@+id/ll_banner"
        android:layout_marginTop="0dp" >

        <FrameLayout
            android:id="@+id/map"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            class="com.google.android.gms.maps.MapFragment" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/ll_banner"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="20dp"
        android:background="@android:color/transparent"
        android:orientation="vertical" >

        <ImageButton
            android:id="@+id/close_map"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/cinemas_close_button_normal"
            android:clickable="true" />
    </LinearLayout>

    <RelativeLayout
        android:id="@+id/rl_location"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_margin="10dp"
        android:background="@android:color/white"
        android:visibility="gone" >

        <com.handmark.pulltorefresh.library.PullToRefreshScrollView
            xmlns:ptr="http://schemas.android.com/apk/res-auto"
            android:id="@+id/pullToRefresh"
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:layout_margin="@dimen/common_padding"
            android:visibility="visible"
            ptr:ptrAnimationStyle="flip"
            ptr:ptrMode="pullFromStart" >

            <LinearLayout
                android:id="@+id/llCinema"
                android:layout_width="fill_parent"
                android:layout_height="match_parent"
                android:layout_margin="10dp"
                android:orientation="vertical" >

                <TextView
                    android:id="@+id/tvNearByCinemas"
                    style="@style/GrayNormalTextView"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:text="NEARBY CINEMAS" />

                <ListView
                    android:id="@+id/list_location"
                    android:layout_width="fill_parent"
                    android:layout_height="match_parent"
                    android:visibility="gone" />

                <LinearLayout
                    android:id="@+id/lLCinemaList"
                    android:layout_width="fill_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical" >
                </LinearLayout>

                <ProgressBar
                    android:id="@+id/pbLoadMoreData"
                    style="?android:attr/progressBarStyle"
                    android:layout_width="30dp"
                    android:layout_height="30dp"
                    android:layout_gravity="center"
                    android:layout_marginBottom="@dimen/common_padding"
                    android:visibility="gone" />
            </LinearLayout>
        </com.handmark.pulltorefresh.library.PullToRefreshScrollView>

        <TextView
            android:id="@+id/tv_msg"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:layout_marginTop="20dp" />
    </RelativeLayout>

    <!--
    <com.insing.insingmoviesapp.custom.SlidingUpPanelLayout
        xmlns:sothree="http://schemas.android.com/apk/res-auto"
        android:id="@+id/sliding_layout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_margin="10dp"
        android:gravity="bottom"
        sothree:dragView="@+id/dragView"
        sothree:panelHeight="68dp"
        sothree:paralaxOffset="100dp"
        sothree:shadowHeight="4dp"
        android:layout_below="@+id/ll_banner" 
        android:visibility="gone">

        MAIN CONTENT

        <View
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:visibility="gone" />
        SLIDING LAYOUT

        <RelativeLayout
            android:id="@+id/rl_location2"
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:background="@android:color/white" >

            <ListView
                android:id="@+id/list_location"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_margin="10dp" >
            </ListView>

            <com.handmark.pulltorefresh.library.PullToRefreshScrollView
                xmlns:ptr="http://schemas.android.com/apk/res-auto"
                android:id="@+id/pullToRefresh2"
                android:layout_width="fill_parent"
                android:layout_height="match_parent"
                android:layout_margin="@dimen/common_padding"
                android:visibility="visible"
                ptr:ptrAnimationStyle="flip"
                ptr:ptrMode="pullFromStart" >

                <LinearLayout
                    android:id="@+id/llCinema"
                    android:layout_width="fill_parent"
                    android:layout_height="match_parent"
                    android:layout_margin="10dp"
                    android:orientation="vertical" >

                    <TextView
                        android:id="@+id/tvNearByCinemas"
                        style="@style/GrayNormalTextView"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:text="NEARBY CINEMAS" />
                    <ListView
                            android:id="@+id/list_location"
                            android:layout_width="fill_parent"
                            android:layout_height="match_parent"
                            android:visibility="gone"/>

                    <LinearLayout
                        android:id="@+id/lLCinemaList"
                        android:layout_width="fill_parent"
                        android:layout_height="match_parent"
                        android:orientation="vertical" >


                    </LinearLayout>

                </LinearLayout>
            </com.handmark.pulltorefresh.library.PullToRefreshScrollView>

            <TextView 
            android:id="@+id/tv_msg"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_marginTop="20dp"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            />


        </RelativeLayout>
    </com.insing.insingmoviesapp.custom.SlidingUpPanelLayout>
    -->

</RelativeLayout>

</ScrollView>