我有一個RecyclerView與項目佈局上啓用「selectableItemBackground」每個項目給我的觸摸漣漪效應。問題是,這些物品上有一個imageView,並且漣漪效應只發生在圖像下。如何在整個項目佈局上顯示漣漪(在imageView上),就像觸摸Google Play商店上的項目一樣?如何在Imageview上有selectableItemBackground?
回答
或者你可以試試這個: -
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="200dp"
android:clickable="true"
android:focusable="true"
card_view:cardCornerRadius="4dp"
android:foreground="?android:attr/selectableItemBackground">
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v7.widget.CardView>
我試過了,selectableItemBackground在觸摸時沒有生效。基本上沒有任何反應。 – SergeantPeauts
我編輯了代碼:)將'android:clickable =「true」'添加到'cardView'中。 – Wizard
可愛的這個工作。除非你需要把注意力集中到真實。 – SergeantPeauts
嘗試在XML文件中使用android:drawSelectorOnTop="true"
在RecyclerView。 並設置Ripple效果選擇器爲android:background
屬性RecyclerView cell。選擇器的
實施例中可繪製-V21夾細胞:具有選擇背景
ripple_selector.xml
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/preference_item_pressed"> <!-- ripple color -->
<item android:id="@android:id/mask">
<color android:color="@android:color/white" />
</item> <!-- normal color -->
</ripple>
細胞和例如:
cell.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="72dp" android:layout_height="72dp"
android:background="@drawable/ripple_selector">
</RelativeLayout>
它仍然在單元格的imageView下。 – SergeantPeauts
您是否已將'android:clickable =「true」 android:focusable =「true」'添加到您的父級佈局中? – mtwain
這其實很好。但它只適用於api 21以上的版本嗎? – SergeantPeauts
我在propiety value ?android:attr/selectableItemBackground"
中解決了父級內容中的設置並啓用了可調焦功能。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:foreground="?android:attr/selectableItemBackground"
android:focusable="true">
<ImageView
android:id="@+id/cover_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:contentDescription="@string/desc_empty"
android:scaleType="centerCrop"
android:src="@drawable/default_image" />
</RelativeLayout>
不錯,使用前景你甚至可以添加不同的背景,並且「新聞」效果依然存在!非常感謝! –
- 1. 如何在imageview上設置imageview?
- 2. 如何在Imageview上繪畫?
- 3. 自定義selectableItemBackground
- 4. selectableItemBackground not found
- 5. RecyclerView安卓:ATTR/selectableItemBackground不上的項目
- 6. ImageView在Android的ImageView上
- 7. 機器人:ATTR/selectableItemBackground
- 8. ?android:attr/selectableItemBackground與另一個現有背景
- 9. 使用SelectableItemBackground沒有紋波效應
- 10. 如何在imageView上點擊全屏顯示imageView?
- 11. 如何在gridView中將imageView投影到imageView上?
- 12. 如何在ImageView上製作橫幅?
- 13. 如何在Webview上覆蓋imageview android
- 14. 如何在Android上顯示RelativeLayout和ImageView?
- 15. 如何在imageview的onclick上實現doubletap?
- 16. 如何在tableViewController上添加一個imageView?
- 17. 如何在imageView上添加視圖?
- 18. 如何在ImageView上實現onClick()方法
- 19. 如何在imageview上應用動畫
- 20. 如何在ImageView上顯示圖像
- 21. 如何在imageview上顯示posterize效果?
- 22. 如何使用%?在LinearLayout上放置ImageView?
- 23. 如何在圖庫上疊加imageview?
- 24. 如何在屏幕上收聽imageview?
- 25. Android中的?selectableItemBackground,?android:selectableItemBackground和?android:attr/selectableItemBackground之間的區別?
- 26. ImageView在TextView上
- 27. 如何在所有屏幕上正確調整imageview的大小?
- 28. 如何在沒有ImageView時將視圖向上移動?
- 29. 如何在imageview的
- 30. 如何使android:background =「?android:attr/selectableItemBackground在API級別8工作
您應該將相同的內容應用於您的項目佈局作爲背景。你可以分享你的佈局。 – cgr