1 2Android ElevationBasic Sample 3=================================== 4 5This sample demonstrates ways to move a view in the z-axis using 6`setTranslationZ()`. This method was introduced in API Level 21 ('Lollipop'). 7 8Introduction 9------------ 10 11This sample uses two shapes, a circle and a square, and it demonstrates two 12alternative ways to move a view in the z-axis. The first shape, the circle, 13has a fixed elevation, which is defined in XML. The second view, the square, 14changes its elevation using [setTranslationZ()][1] when a user touches it: 15 16 shape2.setOnTouchListener(new View.OnTouchListener() { 17 @Override 18 public boolean onTouch(View view, MotionEvent motionEvent) { 19 int action = motionEvent.getActionMasked(); 20 /* Raise view on ACTION_DOWN and lower it on ACTION_UP. */ 21 switch (action) { 22 case MotionEvent.ACTION_DOWN: 23 Log.d(TAG, "ACTION_DOWN on view."); 24 view.setTranslationZ(120); 25 break; 26 case MotionEvent.ACTION_UP: 27 Log.d(TAG, "ACTION_UP on view."); 28 view.setTranslationZ(0); 29 break; 30 default: 31 return false; 32 } 33 return true; 34 } 35 }); 36 37The elevation reverts back once the touch is removed. 38 39[1]: https://developer.android.com/training/material/shadows-clipping.html#Elevation 40 41Pre-requisites 42-------------- 43 44- Android SDK 27 45- Android Build Tools v27.0.2 46- Android Support Repository 47 48Screenshots 49------------- 50 51<img src="screenshots/fixed.png" height="400" alt="Screenshot"/> <img src="screenshots/raised.png" height="400" alt="Screenshot"/> 52 53Getting Started 54--------------- 55 56This sample uses the Gradle build system. To build this project, use the 57"gradlew build" command or use "Import Project" in Android Studio. 58 59Support 60------- 61 62- Google+ Community: https://plus.google.com/communities/105153134372062985968 63- Stack Overflow: http://stackoverflow.com/questions/tagged/android 64 65If you've found an error in this sample, please file an issue: 66https://github.com/googlesamples/android-ElevationBasic 67 68Patches are encouraged, and may be submitted by forking this project and 69submitting a pull request through GitHub. Please see CONTRIBUTING.md for more details. 70 71License 72------- 73 74Copyright 2017 The Android Open Source Project, Inc. 75 76Licensed to the Apache Software Foundation (ASF) under one or more contributor 77license agreements. See the NOTICE file distributed with this work for 78additional information regarding copyright ownership. The ASF licenses this 79file to you under the Apache License, Version 2.0 (the "License"); you may not 80use this file except in compliance with the License. You may obtain a copy of 81the License at 82 83http://www.apache.org/licenses/LICENSE-2.0 84 85Unless required by applicable law or agreed to in writing, software 86distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 87WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 88License for the specific language governing permissions and limitations under 89the License. 90