海拔不工作 [英] Elevation not working
问题描述
我试图让一个按钮 4DP
抬高一个示例应用程序,我似乎无法得到任何的影子出现。
这是我的code:
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:工具=http://schemas.android.com/tools
机器人:layout_width =match_parent
机器人:layout_height =match_parent
工具:上下文=。MainActivity
机器人:clipChildren =假
机器人:方向=垂直>
<按钮
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:文字=点击我
机器人:背景=@绘制/ myrect
机器人:海拔=4DP/>
< / LinearLayout中>
使用我的背景绘制的存在:
<形状的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:形状=矩形>
[固体机器人:颜色=#336699/>
<角落的android:半径=5DP/>
< /形状>
我的app.gradle是:
安卓{
compileSdkVersion 21
buildToolsVersion21.1.1
...
}
这是结果:
我没有看到其他职位,像这样一个同样的问题:<一href=\"http://stackoverflow.com/questions/26572048/elevation-on-android-lollipop-not-working\">Elevation Android上的棒棒糖不工作。他们都指向一个半透明背景的问题,但你可以在这里看到我使用的是完全不透明的。
我失去了我的任何想法?
有关Android版本5.0和放大器;上述尝试高程其他视图。
的android:海拔=10dp
有关按钮,
的android:stateListAnimator =@动画/ button_state_list_animator
button_state_list_animator.xml
&LT;?XML版本=1.0编码=UTF-8? &GT;\r
&LT;选择的xmlns:机器人=http://schemas.android.com/apk/res/android&GT;\r
&LT;项目的android:STATE_ pressed =真正的机器人:state_enabled =真正的&GT;\r
&LT;集&gt;\r
&LT; objectAnimator机器人:propertyName的=translationZ\r
机器人:时间=@整数/ button_ pressed_animation_duration\r
机器人:valueTo =@扪/ button_ pressed_z_material\r
机器人:VALUETYPE =floatType/&GT;\r
&LT; objectAnimator机器人:propertyName的=海拔\r
机器人:时间=0\r
机器人:valueTo =@扪/ button_elevation_material\r
机器人:VALUETYPE =floatType/&GT;\r
&LT; /集&gt;\r
&LT; /项目&GT;\r
&LT;! - 基态 - &GT;\r
&LT;项目的android:state_enabled =真正的&GT;\r
&LT;集&gt;\r
&LT; objectAnimator机器人:propertyName的=translationZ\r
机器人:时间=@整数/ button_ pressed_animation_duration\r
机器人:valueTo =0\r
机器人:startDelay所=@整数/ button_ pressed_animation_delay\r
机器人:VALUETYPE =floatType/&GT;\r
&LT; objectAnimator机器人:propertyName的=海拔\r
机器人:时间=0\r
机器人:valueTo =@扪/ button_elevation_material\r
机器人:VALUETYPE =floatType/&GT;\r
&LT; /集&gt;\r
&LT; /项目&GT;\r
&LT;项目&GT;\r
&LT;集&gt;\r
&LT; objectAnimator机器人:propertyName的=translationZ\r
机器人:时间=0\r
机器人:valueTo =0\r
机器人:VALUETYPE =floatType/&GT;\r
&LT; objectAnimator机器人:propertyName的=海拔\r
机器人:时间=0\r
机器人:valueTo =0\r
机器人:VALUETYPE =floatType/&GT;\r
&LT; /集&gt;\r
&LT; /项目&GT;\r
&LT; /选择&GT;
\r
低于5.0的版本,
的android:背景=@机器人:可绘制/ dialog_holo_light_frame
我的输出:
I'm trying to get a 4dp
elevation on a button in a sample app and I can't seem to get any shadow to show up.
This is my code:
<LinearLayout 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"
tools:context=".MainActivity"
android:clipChildren="false"
android:orientation="vertical">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click me"
android:background="@drawable/myrect"
android:elevation="4dp"/>
</LinearLayout>
With my background drawable being:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#336699" />
<corners android:radius="5dp" />
</shape>
My app.gradle is:
android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
...
}
This is the result:
I did see other posts with the same issue like this one: Elevation on Android Lollipop not working. They all point to a semi-transparent background as the issue, but as you can see here I'm using a full opacity one.
Any idea of what I'm missing?
For android version 5.0 & above try the Elevation for other views..
android:elevation="10dp"
For Buttons,
android:stateListAnimator="@anim/button_state_list_animator"
button_state_list_animator.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:state_enabled="true">
<set>
<objectAnimator android:propertyName="translationZ"
android:duration="@integer/button_pressed_animation_duration"
android:valueTo="@dimen/button_pressed_z_material"
android:valueType="floatType"/>
<objectAnimator android:propertyName="elevation"
android:duration="0"
android:valueTo="@dimen/button_elevation_material"
android:valueType="floatType"/>
</set>
</item>
<!-- base state -->
<item android:state_enabled="true">
<set>
<objectAnimator android:propertyName="translationZ"
android:duration="@integer/button_pressed_animation_duration"
android:valueTo="0"
android:startDelay="@integer/button_pressed_animation_delay"
android:valueType="floatType"/>
<objectAnimator android:propertyName="elevation"
android:duration="0"
android:valueTo="@dimen/button_elevation_material"
android:valueType="floatType" />
</set>
</item>
<item>
<set>
<objectAnimator android:propertyName="translationZ"
android:duration="0"
android:valueTo="0"
android:valueType="floatType"/>
<objectAnimator android:propertyName="elevation"
android:duration="0"
android:valueTo="0"
android:valueType="floatType"/>
</set>
</item>
</selector>
below 5.0 version,
android:background="@android:drawable/dialog_holo_light_frame"
My output:
这篇关于海拔不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!