我想以编程方式设置 TextView 对象的背景,但也想对其产生链式 react 。
我可以在背景设置为 android:selectableItemBackground
时使用,但是在设置背景时涟漪效果会丢失。
我还尝试将 ImageView
与 TextView
放在 FrameLayout
中。并且不将图像设置为 TextView
的背景,而是作为 ImageView
的图像:是的,波纹在那里,但它似乎在图像“后面”。
我是否需要从位图中为背景创建一个RippleDrawable
?我该怎么做?
最佳答案
我遇到了和你一样的问题并使用
修复了它
android:foreground="?attr/selectableItemBackground"
在 FrameLayout 上。
这是示例 FrameLayout:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/more"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:foreground="?attr/selectableItemBackground">
<ImageView
android:id="@+id/discover_carousel_item_image"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical|center_horizontal"
android:scaleType="fitXY" />
</FrameLayout>
关于android - 在 TextView 对象上设置背景并保持波纹效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27579626/