ScrollView嵌套复杂布局

Android的界面布局中为我们提供了ScrollView组件,即当页面的信息过多而超过屏幕时,产生滑动效果来查看页面内容,但是使用时需要注意几点:

1,ScrollView一般与LinearLayout同时使用,之所以使LinearLayout是因为LinearLayout本身的特性,LinearLayout会根据组件来扩展自身的高度,这样在使用ScrollView的时候,会保证所有的内容都能显示出来,而RelativeLayout在使用的时候就会麻烦很多,因为相对布局中,如果以父边框为基准,使用margin来调控距离,不会增加RelativeLayout自身的高度,反而会将子控件的控件压缩,所以在ScrollView与RelativeLayout相结合使用的时候,可以使用padding来调控组件的距离,用扩大组件的宽度或者高度的方法来实现间距的效果。

2,当ScrollView没有fillViewport=“true”时,里面的元素(比如LinearLayout)会按照wrap_content来计算(不论它是否设了” match _parent”) 这个android:fillViewport很重要。

<ScrollView
        android:fillViewport="true"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="3">

        <!--意见-->
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:paddingLeft="10dp">

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

                <TextView
                    android:id="@+id/tv_resopinion"
                    android:layout_width="match_parent"
                    android:layout_height="60dp"
                    android:background="@drawable/shape_advise1"
                    android:gravity="center_vertical"
                    android:paddingBottom="15dp"
                    android:paddingLeft="20dp"
                    android:paddingTop="15dp"
                    android:text="@string/document_idea_resopinion"
                    android:textAppearance="@style/common_text_size"
                    android:textColor="@color/font_gray"/>

                <cn.gov.sz.oa.widget.NoScrollListView
                    android:visibility="gone"
                    android:id="@+id/pull_resopinion"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"/>

                <TextView
                    android:layout_marginTop="15dp"
                    android:id="@+id/tv_leader_idea"
                    android:layout_width="match_parent"
                    android:layout_height="60dp"
                    android:background="@drawable/shape_advise1"
                    android:gravity="center_vertical"
                    android:paddingBottom="15dp"
                    android:paddingLeft="20dp"
                    android:paddingTop="15dp"
                    android:text="@string/document_title_idea"
                    android:textAppearance="@style/common_text_size"
                    android:textColor="@color/font_gray"/>

                <cn.gov.sz.oa.widget.NoScrollListView
                    android:id="@+id/lv_leader_idea"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"/>
            </LinearLayout>

            <include layout="@layout/content_empty"/>

        </RelativeLayout>
    </ScrollView>

3,如果ScrollView嵌套的布局中包括有自带滚动的控件,会将自带滚动上面的一些控件挤出屏幕,原因是这些控件失去了焦点,解决方案就是给最顶端的控件设置获取焦点。

    view.setFocusable(true);
    view.setFocusableInTouchMode(true);
    view.requestFocus();
  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值