0

我试图弄清楚当您按下它时如何突出显示整个 GridView 单元格,就像在 Google Play 商店中一样。这是我正在尝试做的事情的图像(咆哮的天空细胞是我想要完成的):

在此处输入图像描述

我知道您可以为图像/视图使用选择器,但这只会更改背景颜色,不会覆盖单元格中的图像(除非有一些我还没有找到的特殊技巧/开关)。我试图在单元格的整个内容上(而不是在图像下方)覆盖半透明颜色,而选择器似乎没有这样做。我也知道您可以将 .setColorFilter() 与 OnTouchListener 一起使用,但这仅适用于 Drawables(据我所知),我认为使用 GridView 实现会很痛苦。在 Google Play 商店中,整个单元格被突出显示,其中包含多个不同的视图。

目前,我有一个带有自定义背景的 GridView 设置,以使其具有卡片般的外观。它有一个 ImageView 和几个 TextView,但我不知道如何突出显示整个 GridView 单元格(覆盖半透明颜色)。通常我会提供代码,但在这种情况下,我不确定它是否会有所帮助,因为我目前得到的是非常标准的。关于如何实现的任何想法?

4

2 回答 2

1

干得好。

在 xml 中使用属性 drawSelectorOnTop="false"。

或尝试mGridview.setDrawSelectorOnTop(true)

希望它有所帮助。

于 2013-10-31T16:10:03.910 回答
0

像这样试试

它可以通过Selector来实现。

在 grid_cell_item 的根布局上使用选择器作为背景

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/artists_list_backgroundcolor"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/home_grid_img"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:contentDescription="@string/app_name" />

    <TextView
        android:id="@+id/home_grid_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/home_grid_img"
        android:layout_centerHorizontal="true"
        android:textColor="#7a7a7a"
        android:textSize="12sp"
        android:textStyle="bold" />

</RelativeLayout>

艺术家列表背景色.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
 <item 
 android:state_selected="false"
    android:state_pressed="false" 
    android:drawable="@color/white" />
<item android:state_pressed="true" 
    android:drawable="@color/itemselected" />
<item android:state_selected="true"
 android:state_pressed="false" 
    android:drawable="@color/itemselected" />
</selector> 

颜色.xml

<resources>
    <color name="white">#ffffff</color>
    <color name="itemselected">#EDEDED</color>

</resources>

希望这会帮助你。

于 2013-10-27T05:36:44.577 回答