2019-10-18 ScrollView流畅滑动

ScrollView内只能套一个布局,不然编译不通过,但是这个布局中可以放多个布局及控件,但是如果内容过长,会使得屏幕滑动不流畅,尤其是其中有多个RecyclerView时,这时候需要在RecyclerView中添加一个属性nestedScrollingEnabled,才可以解决这个小问题。
<android.support.v7.widget.RecyclerView
          android:id="@+id/rv_brand"
          android:layout_width="match_parent"
          android:nestedScrollingEnabled="false"
          android:layout_height="260dp">
 </android.support.v7.widget.RecyclerView>
另外多个模块之间滑动时,会出现嵌套的问题,这个问题解决方法如下:
//在ScrollView内,用一个相对布局作为总布局,并在其中设置一个属性descendantFocusability
<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:descendantFocusability="blocksDescendants">
</RelativeLayout>
还有一种横向滑动叫HorizontalScrollView,用法如下:
    <HorizontalScrollView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:scrollbars="none">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/dp_51"
                    android:gravity="center_vertical"
                    android:orientation="horizontal">

                    <TextView
                        android:id="@+id/tv_goHome"
                        android:layout_width="@dimen/dp_68"
                        android:layout_height="@dimen/dp_23"
                        android:layout_marginLeft="@dimen/dp_30"
                        android:background="@drawable/selector_smart_house_huijia"
                        android:clickable="true"
                        android:gravity="center_vertical"
                        android:paddingLeft="@dimen/dp_16"
                        android:text="@string/gohome"
                        android:textColor="@drawable/selector_smart_house_text"/>

                    <TextView
                        android:id="@+id/tv_leaveHome"
                        android:layout_width="@dimen/dp_68"
                        android:layout_height="@dimen/dp_23"
                        android:layout_marginLeft="@dimen/dp_30"
                        android:background="@drawable/selector_smart_house_lijia"
                        android:clickable="true"
                        android:gravity="center_vertical"
                        android:textColor="@drawable/selector_smart_house_text"
                        android:paddingLeft="@dimen/dp_16"
                        android:text="@string/leavehome" />
                </LinearLayout>
            </HorizontalScrollView>

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容