Android 5.0 android: elevation if you set the effect for the button, androidelevation
Android 5.0 provides the elevation function. I downloaded the Android sample code in SDK Manager and read the ElevationBasic example. Two view objects, one circle and one rectangle, are displayed, android: elevation = 30dp is set in the circle. The example is as follows:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
<? xml version = "1.0" encoding = "utf-8" ?> <!-- Copyright 2014 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. - --> < FrameLayout 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/floating_shape_2" android:layout_width = "80dp" android:layout_height = "80dp" android:layout_marginLeft = "25dp" android:background = "@drawable/shape2" android:layout_gravity = "center" /> </ FrameLayout > |
Run the following example in Nexus 9:
If I replace the component with a Button and remove other attributes of the Button, the elevation effect will not be displayed, as shown below:
The button style of the default topic contains the android: elevation and android: translationZ attributes. You can remove the default property animation and set your own android: stateListAnimator attributes.
The following code
123456789 |
< Button ... android:stateListAnimator = "@null" /> < Button ... android:stateListAnimator = "@anim/my_animator" /> |
The default animation (animator) is defined in button_state_list_anim_material.xml. Here is an example of a button that is unavailable and clicked
12345678910111213141516171819202122232425262728293031 |
<? 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 > <! -- Basic status --> < 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 > ... </ selector >
|
Address: http://www.itmmd.com/201412/240.html
This article is organized and published by Meng IT personnel. The reprinted article must indicate the source.