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

相关文章
|
Prometheus 监控 Cloud Native
Prometheus PromQL语法
Prometheus PromQL语法
1027 0
|
安全 Shell 测试技术
Android 11 来袭,一起来看看怎么适配(二)
Android 11 来袭,一起来看看怎么适配
Cannot access ‘androidx.lifecycle.HasDefaultViewModelProviderFactory‘ which is a supertype of ‘com.e
今天创建了个项目,突然出现了这样的问题,怎么处理都没用,网上找了一堆没发现答案,故此记录。
456 0
Cannot access ‘androidx.lifecycle.HasDefaultViewModelProviderFactory‘ which is a supertype of ‘com.e
RecyclerView GridView模式同一行,使其高度平齐,自动适应高度最大item
RecyclerView GridView模式同一行,使其高度平齐,自动适应高度最大item
632 0
|
9月前
|
人工智能 Kubernetes Cloud Native
跨越鸿沟:PAI-DSW 支持动态数据挂载新体验
本文讲述了如何在 PAI-DSW 中集成和利用 Fluid 框架,以及通过动态挂载技术实现 OSS 等存储介质上数据集的快速接入和管理。通过案例演示,进一步展示了动态挂载功能的实际应用效果和优势。
|
人工智能 安全 机器人
2023云栖大会,Salesforce终敲开中国CRM市场
2023云栖大会,Salesforce终敲开中国CRM市场
RecyclerView的item不充满的整个宽度的原因
RecyclerView的item不充满的整个宽度的原因
|
XML 前端开发 Android开发
Android 实现圆弧背景(Shape实现和自定义View)
如今Android系统的App,很多时候为了有更好的用户体验,都会有各种好看的UI,动画,点击效果等等,其中圆弧的控件在App中很常见,今儿就自己总结下自己实现圆弧的两种基础的方法。即Shape方法和使用View里面的方法自己画。
|
存储 分布式计算 大数据
【云计算与大数据技术】大数据系统总体架构概述(Hadoop+MapReduce )
【云计算与大数据技术】大数据系统总体架构概述(Hadoop+MapReduce )
775 0
|
安全 JavaScript 前端开发
escape, encodeURI, encodeURIComponent 有什么区别以及作用?
escape, encodeURI, encodeURIComponent 有什么区别以及作用?
457 0