【问题标题】:Etsy's Android Staggered Gridview - drawSelectorOnTopEtsy 的 Android 交错网格视图 - drawSelectorOnTop
【发布时间】:2014-05-13 02:18:13
【问题描述】:
我正在尝试使用 Etsy 的交错网格视图 (https://github.com/maurycyw/StaggeredGridView),并且我的工作大部分都按预期工作,除了我在尝试让选择器在顶部绘制时遇到问题。
我试过使用 mGridView.setDrawSelectorOnTop(true);和 android:drawSelectorOnTop="true" 在布局中,但还没有成功。有谁碰巧解决了这个问题,或者知道图书馆在当前状态下是否不可能?
【问题讨论】:
标签:
android
gridview
staggered-gridview
【解决方案1】:
令人沮丧的是,Etsy 的 StaggeredGrid 不支持项目选择器可绘制对象。要解决此问题,请在 GridView item 上设置选择器,而不是 GridView 本身。
在我当前的项目中,我将 GridView 项包装在 FrameLayout 中,因为 FrameLayout 具有 android:foreground 属性:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:foreground="?android:attr/selectableItemBackground">
<!-- Your item layout goes here. -->
</FrameLayout>
?android:attr/selectableItemBackground 为您提供标准的蓝色突出显示。如果需要,您可以使用自己的可绘制状态列表。