Android 中RelativeLayout 中的scrollview无法滑动

来源:互联网 发布:上传小说的软件 编辑:程序博客网 时间:2024/05/21 15:47

   最近写一个项目要实现把一个界面除去头部和底部布局的内容截图保存并分享,由于内容多一个界面显示不全,最初我是将我要保存的内容放在网页中,然后将网页中的内容保存为图片,但是这样做保存比较慢。后来觉得将网页内容截图会比较方便。这样是可以实现。之后发现还有一种方法。就是在RelativeLayout 中放入一个scrollview,之后将scrollview中的内容截图保存。

RelativeLayout中如果添加的scrollview组件超过屏幕的高度,会被底部的布局挡住,显示不全,或者无法滑动,我经过查阅发现在relativelayout中添加scrollview 是可以的,需要使用自上而下的布局,或者使用padding来增加组件的宽度或者高度 。布局如下:

总体布局是RelativeLayout,里面第一个子布局RelativeLayout 放在头部,第二个子布局RelativeLayout 放在底部,第三个子布局RelativeLayout放在中间,里面包含一个scrollview就可以实现滑动。贴上代码

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
     android:background="@color/topBg"
    android:orientation="vertical" >


    <RelativeLayout
        android:id="@+id/header"
        android:layout_width="fill_parent"
        android:layout_height="@dimen/height_10_80"
        android:layout_alignParentTop="true"
         >


        <Button
            android:id="@+id/invitemingpian_back"
            android:layout_width="@dimen/height_4_80"
            android:layout_height="@dimen/height_4_80"
            android:layout_centerVertical="true"
            android:layout_marginLeft="@dimen/height_1_80"
            android:background="@drawable/back" />


        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="邀请名片"
            android:textColor="@color/white"
            android:textSize="21.0sp" />
    </RelativeLayout>


    <LinearLayout
        android:id="@+id/header11"
        android:layout_width="fill_parent"
        android:layout_height="@dimen/height_8_80"
        android:layout_alignParentBottom="true"
     
        android:orientation="vertical" >


        <View
            android:layout_width="match_parent"
            android:layout_height="0.1dip"
            android:background="@color/grey" />


        <LinearLayout
            android:id="@+id/view_01"
            android:layout_width="fill_parent"
            android:layout_height="@dimen/height_8_80"
            android:background="#fbfbfb"
            android:gravity="center"
            android:padding="@dimen/height_1_80"
            android:orientation="horizontal" >


            <LinearLayout
                android:id="@+id/huan"
                android:layout_width="0dip"
                android:layout_height="@dimen/height_6_80"
                android:layout_margin="@dimen/height_1_80"
                android:layout_weight="1"
                android:background="@drawable/blue_dark_bg"
                android:gravity="center"
                android:orientation="horizontal" >


                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:drawableLeft="@drawable/refersh"
                    android:gravity="center"
                    android:text="换一张"
                    android:textColor="@color/white"
                    android:textSize="20sp" />
            </LinearLayout>


            <TextView
                android:id="@+id/fenxiang"
                android:layout_width="0dip"
                android:layout_height="@dimen/height_6_80"
                android:layout_margin="@dimen/height_1_80"
                android:layout_weight="1"
                android:background="@drawable/pink_dark_bg"
                android:gravity="center"
                android:text="保存图片并分享"
                android:textColor="@color/white"
                android:textSize="20sp" />
        </LinearLayout>
    </LinearLayout>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/header11"
        android:layout_below="@+id/header"
        android:orientation="vertical" >


        <include
            android:id="@+id/include_scorll"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            layout="@layout/scroll" />
    </LinearLayout>


</RelativeLayout>

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    
    android:fadingEdgeLength="0.0dip"
    android:scrollbars="none" >


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >


        <LinearLayout
            android:id="@+id/mainlinearlayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/background"
            android:gravity="center"
            android:orientation="vertical"
             >


            <ImageView
                android:id="@+id/erweima_img"
                android:layout_width="@dimen/height_23_80"
                android:layout_height="@dimen/height_23_80"
                android:layout_marginTop="@dimen/height_21_80" />
        </LinearLayout>


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/white"
            android:orientation="horizontal"
            android:padding="15dip" >


            <ImageView
                android:id="@+id/user_img"
                android:layout_width="@dimen/height_6_80"
                android:layout_height="@dimen/height_6_80" />


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="@dimen/height_1_80"
                android:orientation="vertical" >


                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/height_3_80"
                    android:gravity="center"
                    android:orientation="horizontal" >


                    <TextView
                        android:id="@+id/username_text"
                        android:layout_width="wrap_content"
                        android:layout_height="@dimen/height_4_80"
                        android:layout_alignParentLeft="true"
                        android:gravity="center"
                        android:text="" />


                    <TextView
                        android:id="@+id/time_text"
                        android:layout_width="@dimen/height_13_80"
                        android:layout_height="@dimen/height_4_80"
                        android:layout_alignParentRight="true"
                        android:gravity="center"
                        android:text="2015-09-30"
                        android:textSize="@dimen/text_4" />
                </RelativeLayout>


                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="@dimen/height_4_80"
                    android:text=""
                    android:gravity="center"
                    android:textColor="@color/red" />
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>


</ScrollView>

0 0
原创粉丝点击