Seeing the elevation feature in the android5.0 version, I downloaded the Android 5.0 example code from SDK Manager, looked at the Elevationbasic example, showed 2 view objects, a circular rectangle, a circle set Ndroid:elevation = 30DP, specific examples are as follows
<?xml version= "1.0" encoding= "Utf-8"?><!--Copyright the Android Open Source Project Licensed under Apache License, Version 2.0 (the "License"); You are not a use of this file except in compliance with the License. Obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 unless required by applicable Law or agreed into writing, software distributed under the License is distributed on a "as is" BASIS, without Warra Nties or CONDITIONS of any KIND, either express OR implied. See the License for the specific language governing permissions and limitations under the License.---> <framelayou T 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" > <view Android:id= "@+id/floating_shape" android:layout_width= "80DP" Android:layout_height= "80DP" android:layout_marginright= "40DP" android:background= "@drawable/shape" android:elevation= "30DP" android:layout_gravity= "center"/> <view android:id= "@+id/floati Ng_shape_2 "android:layout_width=" 80DP "android:layout_height=" 80DP "Android:layout_margi nleft= "25DP" android:background= "@drawable/shape2" android:layout_gravity= "center"/></framelay Out>
Run this example in Nexus 9 to get the effect as follows
If I change the component to a button and remove the other properties of the button, the elevation effect is not displayed, as follows
The default theme's button styles include the Android:elevation and Android:translationz properties, you can remove the default property animations, and set your own Android:statelistanimator properties
The following code
<button ... Android:statelistanimator= "@null"/> <button ... Android:statelistanimator= "@anim/my_animator"/>
The default animation (animator) is defined in the Button_state_list_anim_material.xml. Here is an example of a display state that is not available and the button is in the click state
<?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> <o Bjectanimator android:propertyname= "Translationz" android:duration= "@integer/button_pressed_ani Mation_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> <!--basic status--<item android: State_enabled= "true" > <set> <objectanimator android:propertyname= "Translationz" Android:duration= "@integEr/button_pressed_animation_duration "android:valueto=" 0 "android:st artdelay= "@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> ... </selector>
Original address: http://www.itmmd.com/201412/240.html
This article by Meng Meng's IT person to organize the release, reprint must indicate the source.
Android 5.0 Android:elevation If the button is set to effect