android - ImageButton 透明背景的阴影
问题描述
我有一个图像按钮。当我添加透明背景时,阴影消失了。如何在没有第三方库的情况下修复它?
<ImageButton
android:id="@+id/player_activity_previous_button"
android:background="@android:color/transparent"
android:tint="@color/color_for_buttons"
android:src="@drawable/ic_skip_previous_48"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_toLeftOf="@id/player_activity_play_pause_button"
android:layout_centerVertical="true"
android:stateListAnimator="@null"
android:elevation="4dp"
android:translationZ="4dp"/>
解决方案
您可以使用 cardView 和 imageView 的组合而不是具有透明背景的 imageButton,首先但在 gradle 文件中添加一个依赖项。
dependencies {
compile 'com.android.support:cardview-v7:23.0.1'
-------
}
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardElevation="8dp"
card_view:cardBackgroundColor="@android:color/white">
<ImageView
android:id="@+id/dish_image"
android:layout_width="match_parent"
android:layout_height="120dp"
android:adjustViewBounds="true" />
增加阴影效果只需增加卡片高度
推荐阅读
- r - 如何在 R 中建立一个简单的伽马分布模型?
- r - 将 Data.Tables (R) 与循环或映射组合
- html - 我有一个关于在 django 中显示带有条件的数据和 html 元素的问题
- reactjs - 如何访问 componentDidMount 中的 props
- javascript - 如何让使用背面可见性的图像在转换后不消失?
- jenkins - 如何获取依赖于 Jenkins 中某个插件的插件?
- python - wsl 2 上的 pipenv 自定义脚本:shlex.py instream 对象没有读取属性
- node.js - 将 npm install 的输出复制到 docker 容器
- sql - 我得到 ORA-00928 试图插入新数据
- ember.js - 如何从 Ember 路由模型钩子传递 @tracked 对象