【发布时间】:2014-06-07 03:29:22
【问题描述】:
我知道 Picasso 设置了“src”,因此让“image.background”保持平静,但我似乎无法让 ImageView 响应选择器(如触摸它以显示标准全息选择器或任何自定义一)。
有人有工作样本吗?我肯定错过了什么。我尝试了不同的选择器,但没有看到触摸状态。
我已经尝试在 onClick() 中执行 setselected(true),但我知道如果存在具有以下状态的可绘制对象,则视图会自动处理:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false" android:drawable="@android:color/transparent" />
<!-- Even though these two point to the same resource, have two states so the drawable will invalidate itself when coming out of pressed state. -->
<item android:state_focused="true" android:state_enabled="false" android:state_pressed="true" android:drawable="@drawable/abc_list_selector_disabled_holo_light" />
<item android:state_focused="true" android:state_enabled="false" android:drawable="@drawable/abc_list_selector_disabled_holo_light" />
<item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/abc_list_selector_background_transition_holo_light" />
<item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/abc_list_selector_background_transition_holo_light" />
<item android:state_focused="true" android:drawable="@drawable/abc_list_focused_holo" />
</selector>
加载图片的Java代码是:
Picasso.with(mContext).load(url).error(R.drawable.error).fit().into(holder.someIV);
someIV 的 XML 看起来像:
<ImageView
android:id="@+id/list_item_image"
android:layout_width="match_parent"
android:layout_height="@dimen/mixset_list_image_size"
android:layout_marginTop="1dp"
android:layout_marginLeft="1dp"
android:layout_marginRight="1dp"
android:contentDescription="@string/mixes"
android:scaleType="centerCrop"
android:background="@drawable/mix_list_art_selector"
android:cropToPadding="false" />
背景设置为上述选择器。
有什么想法吗?谢谢。
【问题讨论】:
-
也许您的图像覆盖了背景高光?试试this answer。
-
成功了。谢谢!
标签: android android-imageview picasso