Android 安卓升高正常按钮
我一直在到处寻找一种方法来获得一个“凸起”的圆形矩形按钮,而不用完全自己使用背景和自定义视图。我想要这样的按钮: 我以为这样就行了:Android 安卓升高正常按钮,android,button,android-5.0-lollipop,Android,Button,Android 5.0 Lollipop,我一直在到处寻找一种方法来获得一个“凸起”的圆形矩形按钮,而不用完全自己使用背景和自定义视图。我想要这样的按钮: 我以为这样就行了: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:l
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MyActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter the Danger Zone"
android:id="@+id/btn"
android:elevation="8dp" <!-- Here -->
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="16dp"/>
</RelativeLayout>
尝试添加状态列表动画师:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_enabled="true"
android:state_pressed="true">
<set>
<objectAnimator
android:duration="@android:integer/config_shortAnimTime"
android:propertyName="translationZ"
android:valueTo="8dp"
android:valueType="floatType" />
</set>
</item>
<item>
<set>
<objectAnimator
android:duration="@android:integer/config_shortAnimTime"
android:propertyName="translationZ"
android:valueTo="2dp"
android:valueType="floatType" />
</set>
</item>
</selector>
我也遇到了一个类似的问题,我认为是由于错误地夸大了布局,但似乎添加了clipToPadding就成功了。
必须将其设置为包含要投射阴影的视图的父视图组
<YourParentLayout
...
android:clipToPadding="false"
...
像这样:@anim/btn\u anim(如果你不使用样式,也可以直接在你的按钮上)。但是,我希望有一种更优雅的方法来做到这一点。@Charles:android:stateListAnimator=“@null”
将删除库存stateListAnimator
,允许android:elevation
工作。对于我之前的评论,我深表歉意——我被打断了,无法完成。我的目标是,android:elevation应该控制这一点,我想问你是使用appcompat-v7还是原生API Level 21Theme.Material
和kin。但是,我可以使用Theme.Material.Light
重现您的问题,我无法解释它。它在appcompat-v7中是否有效?理论上是的,但理论上现在应该有效。我已经使用ElevationBasic
SDK示例进行了询问,该示例也展示了这种明显的破坏行为。