GridView中android:listSelector="@color/transparent"和="@null"的区别

本文介绍了解决GridView中item点击时出现默认样式的问题。通过设置上层控件的listSelector属性为透明色,成功避免了点击时显示橘黄色尖角的情况。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本来想为GridView中的item添加圆角样式,但添加完press时四角总有橘黄色尖角。在试了不是定义的selector问题后想到可能是冒泡到上层控件了。上层控件属性android:listSelector="@null"本来是解决滚动时默认变黑问题的,然而问题就出在这里。这里的@null并没有屏蔽默认点击样式,这样的话换成"@color/transparent"就好了。

transparent是定义的透明色#00000000
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/gradient_background" tools:context="com.jd.projects.wlw.shuhai.ShuhaiSp"> <!-- <!– 顶部工具栏 –>--> <RelativeLayout android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#44bd32"> <Button android:id="@+id/back_button4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentStart="true" android:layout_marginStart="8dp" android:layout_marginTop="8dp" android:layout_marginEnd="8dp" android:layout_marginBottom="8dp" android:background="@android:color/transparent" android:contentDescription="返回上一页" android:foreground="?android:attr/selectableItemBackground" android:text="返回" android:textColor="@android:color/white" android:textSize="19dp" /> </RelativeLayout> <!-- 视频播放区域 --> <FrameLayout android:id="@+id/video_container" android:layout_width="match_parent" android:layout_height="90dp" android:layout_above="@+id/thumbnail_scrollview" android:layout_below="@id/toolbar" android:layout_marginTop="0dp" android:background="@android:color/black"> <!-- <ProgressBar--> <!-- android:id="@+id/video_loading"--> <!-- android:layout_width="wrap_content"--> <!-- android:layout_height="wrap_content"--> <!-- android:layout_gravity="center" />--> <VideoView android:id="@+id/video_view" android:layout_width="match_parent" android:layout_height="400dp" android:gravity="center" android:text="视频播放区域" android:textColor="@android:color/white" android:visibility="visible" /> </FrameLayout> <!-- 缩略图区域 --> <ScrollView android:id="@+id/thumbnail_scrollview" android:layout_width="match_parent" android:layout_height="290dp" android:layout_alignParentBottom="true" android:fillViewport="true"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <android.widget.GridLayout android:id="@+id/gridLayout" android:layout_width="match_parent" android:layout_height="match_parent" android:alignmentMode="alignBounds" android:columnCount="2" android:padding="8dp" android:rowCount="0" android:background="#ffffff" android:useDefaultMargins="true"> <ImageView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_columnWeight="1" android:layout_margin="4dp" android:adjustViewBounds="true" android:contentDescription="缩略图" android:src="@drawable/default_thumbnail" /> </android.widget.GridLayout> </LinearLayout> </ScrollView> </RelativeLayout>解决布局文件中<ImageView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_columnWeight="1" android:layout_margin="4dp" android:adjustViewBounds="true" android:contentDescription="缩略图" android:src="@drawable/default_thumbnail" />缩略图没有显示在<android.widget.GridLayout android:id="@+id/gridLayout" android:layout_width="match_parent" android:layout_height="match_parent" android:alignmentMode="alignBounds" android:columnCount="2" android:padding="8dp" android:rowCount="0" android:background="#ffffff" android:useDefaultMargins="true">这一模块中
最新发布
06-27
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值