RecycleView 不显示、显示不全及滑动卡顿

简介: RecycleView 出现的不显示或显示不全。ScrollView中嵌套RecycleView滑动出现卡顿。

RecycleView 出现的不显示或显示不全。


1.<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来计算。


相关推荐


Android RecyclerView的Adapter和ViewHolder

相关文章
|
缓存 Android开发
Android RecyclerView 实现瀑布流
Android RecyclerView 实现瀑布流
计算机毕业设计 图书管理系统 Vue+SpringBoot+MySQL(二)
计算机毕业设计 图书管理系统 Vue+SpringBoot+MySQL
386 2
|
Prometheus 监控 Cloud Native
Prometheus PromQL语法
Prometheus PromQL语法
1299 0
|
人工智能 Java
通过okhttp调用SSE流式接口,并将消息返回给客户端
通过okhttp调用SSE流式接口,并将消息返回给客户端
RecyclerView的item不充满的整个宽度的原因
RecyclerView的item不充满的整个宽度的原因
|
Android开发 开发者
Cocos Creator Android 平台接入 Google Firebase (Analytics功能)(一)
Cocos Creator Android 平台接入 Google Firebase (Analytics功能)
624 1
|
Android开发 Kotlin 索引
Android Compose——ScrollableTabRow和LazyColumn同步滑动
Android Compose——ScrollableTabRow和LazyColumn同步滑动
691 0
|
存储 分布式计算 大数据
【云计算与大数据技术】大数据系统总体架构概述(Hadoop+MapReduce )
【云计算与大数据技术】大数据系统总体架构概述(Hadoop+MapReduce )
905 0
|
SQL 人工智能 缓存

热门文章

最新文章