Android_UI开发总结(三):ConstraintLayout中recycleview空白处点击不生效问题

本文探讨了使用ConstraintLayout布局时遇到的问题,特别是点击事件在某些情况下不起作用的现象,并提供了使用FrameLayout替代的解决方案。
  • 先附上constraintLayout的布局文件
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.utils.PullExtendLayout
        android:id="@+id/contact_pull_extend_layout_parent"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <com.ui.ContactExtendListHeader
            android:id="@+id/search_header"
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:layout_marginStart="10dp"
            android:layout_marginEnd="10dp"/>

        <com.utils.CustomRecyclerView
            android:id="@+id/recyclerView"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </com.utils.PullExtendLayout>

    <TextView
        android:id="@+id/empty_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="sorry, no data to show"
        android:textSize="20sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>


</android.support.constraint.ConstraintLayout>
  • 附上recyclerview 相应的adapter中的的部分代码
@Override
    public void onBindViewHolder(ListItemViewHolder holder, int position) {
        // TODO: 2018/5/16 适配渲染的数据到view中,提供的是一个holder
        ListItemViewHolder viewHolder = holder;
        final Object mObject = mMemberData.get(position);
        viewHolder.itemView.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, DetailActivity.class);
                context.startActivity(intent);
            }
        });

此时发现在每一个item空白处点击时,有时不生效,需要下拉出所有数据item之后才点击有效。后来通过打开手机设置>开发者选项>显示布局边界查看发现有的item绘制出来的宽度并没有match_parent。这就是问题关键。
原因是在constraintLayout中又套上子布局时,子布局的android:layout_width不一定生效,具体怎么修改好比较复杂,这样选择替换成效率更高的FrameLayout布局来实现这个效果。
注意,在各种布局中,虽然ConstraintLayout布局比较容易实现开发,但是就效率而言,FrameLayout>RelateLayout>LinearLayout>ConstraintLayout。所以较简单布局要用效率高的布局。
- 附上修改后的布局文件

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.utils.PullExtendLayout
        android:id="@+id/pull_extend_layout_parent"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <com.ui.ContactExtendListHeader
            android:id="@+id/search_header"
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:layout_marginEnd="10dp"
            android:layout_marginStart="10dp"/>

        <com.utils.CustomRecyclerView
            android:id="@+id/recyclerView"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </com.utils.PullExtendLayout>

    <TextView
        android:id="@+id/empty_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="sorry, no data to show"
        android:textSize="20sp"
       android:layout_gravity="center"/>
</FrameLayout>
如果您下载了本程序,但是该程序存在问题无法运行,那么您可以选择退款或者寻求我们的帮助(如果找我们帮助的话,是需要追加额外费用的)。另外,您不会使用资源的话(这种情况不支持退款),也可以找我们帮助(需要追加额外费用) 随着移动互联网技术的发展和用户需求的变化,【小程序名称】应运而生,以其轻量化、便捷化的设计理念为用户提供了一种全新的服务模式。作为一款无需下载安装即可使用的应用,【小程序名称】依托于微信庞大的生态系统,让用户在微信内就能轻松实现各种功能操作。 【小程序名称】的核心功能主要集中在【具体服务领域】,例如在线购物、本地生活服务、教育学习或健康管理等。它简化了传统APP繁琐的注册登录流程,支持微信一键授权登录,极大地提升了用户体验。用户通过搜索或扫描二维码,瞬间即可开启使用,享受快速加载、流畅运行的服务。 该小程序界面设计简洁明了,布局合理,易于上手。同时,其特色功能如实时更新的信息推送、个性化推荐以及社交分享功能,让用户能够及时获取所需信息,并方便地将优质内容分享至朋友圈或好友,实现信息的高效传播与互动。 【小程序名称】注重数据安全与隐私保护,严格遵守国家法律法规和微信平台的规定,确保用户数据的安全无虞。此外,其背后的开发团队持续迭代更新,根据用户反馈不断优化产品性能,提升服务质量,致力于打造一个贴近用户需求、充满活力的小程序生态。 总结来说,【小程序名称】凭借其小巧便携、快捷高效的特性,不仅节省了用户的手机存储空间,更为用户提供了无缝衔接的便利服务,是现代生活中不可或缺的一部分,真正实现了“触手可及”的智能生活新体验。只需轻点屏幕,无限精彩尽在掌握之中。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值