ScrollView中嵌套RecycleView出现的不显示,显示不全及滑动卡顿及ScrollView禁止滚动到中间

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/g984160547/article/details/78246925

RecycleView 出现的不显示,显示不全。解决如下:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/mrc_protocols"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/mdp_10"
        android:layout_marginRight="@dimen/mdp_12"
        android:divider="@null"
        android:scrollbars="none" />
</RelativeLayout>

ScrollView中嵌套RecycleView滑动出现卡顿。解决如下:

LinearLayoutManager linearLayoutManager = new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false) {
    @Override
    public boolean canScrollVertically() {
        return false;
    }
};
//初始化视图
mrcProtocols.setLayoutManager(linearLayoutManager);

ScrollView   顶部子控件  加这2个属性 

android:focusable="true"
android:focusableInTouchMode="true" 
他就不会自动滚动到中间了~
如 

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

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

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:text="顶部控件" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="一堆控件" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="两堆控件" />
    </LinearLayout>
</ScrollView>
Android 使用ScrollView属性fillViewport解决android布局不能撑满全屏的问题
使用了ScrollView嵌套LinearLayout时,在大屏幕手机如三星note3手机上下面会留白,问题的解决办法是在第一层LinearLayout里面嵌套多个LinearLayout,最重要的是将ScrollView中android:fillViewport设置为true。 
当ScrollView里的元素想填满ScrollView时,使用”fill_parent”是不管用的,必需为ScrollView设置:android:fillViewport=”true”。
当ScrollView没有fillVeewport=“true”时, 里面的元素(比如LinearLayout)会按照wrap_content来计算(不论它是否设了”fill_parent”),而如果LinearLayout的元素设置了fill_parent,那么也是不管用的,因为LinearLayout依赖里面的元素,而里面的元素又依赖LinearLayout,这样自相矛盾.所以里面元素设置了fill_parent,也会当做wrap_content来计算.

猜你喜欢

转载自blog.csdn.net/g984160547/article/details/78246925
今日推荐