1<?xml version="1.0" encoding="UTF-8"?> 2<!-- 3 Copyright 2014 The Android Open Source Project 4 5 Licensed under the Apache License, Version 2.0 (the "License"); 6 you may not use this file except in compliance with the License. 7 You may obtain a copy of the License at 8 9 http://www.apache.org/licenses/LICENSE-2.0 10 11 Unless required by applicable law or agreed to in writing, software 12 distributed under the License is distributed on an "AS IS" BASIS, 13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 See the License for the specific language governing permissions and 15 limitations under the License. 16--> 17 18 19 20<sample> 21 <name>ElevationBasic</name> 22 <group>UI</group> 23 <package>com.example.android.elevationbasic</package> 24 25 <!-- change minSdk if needed--> 26 <minSdk>21</minSdk> 27 28 <strings> 29 <intro> 30 <![CDATA[ 31 This sample demonstrates two alternative ways to move a view in the z-axis. The 32 first view has a fixed elevation using XML and the second one is raised when the user 33 taps on it, using setTranslationZ(). 34 ]]> 35 </intro> 36 <sample_action>Elevation Basic</sample_action> 37 </strings> 38 39 <template src="base"/> 40 <template src="FragmentView"/> 41 <common src="logger"/> 42 <common src="activities"/> 43 <metadata> 44 <status>PUBLISHED</status> 45 <categories>UI, Input</categories> 46 <technologies>Android</technologies> 47 <languages>Java</languages> 48 <solutions>Mobile</solutions> 49 <level>BEGINNER</level> 50 <icon>screenshots/icon-web.png</icon> 51 <screenshots> 52 <img>screenshots/fixed.png</img> 53 <img>screenshots/raised.png</img> 54 </screenshots> 55 <api_refs> 56 <android>android.view.MotionEvent</android> 57 </api_refs> 58 <description> 59<![CDATA[ 60This sample demonstrates ways to move a view in the z-axis using 61`setTranslationZ()`. This method was introduced in API Level 21 ('Lollipop'). 62]]> 63 </description> 64 <intro> 65<![CDATA[ 66This sample uses two shapes, a circle and a square, and it demonstrates two 67alternative ways to move a view in the z-axis. The first shape, the circle, 68has a fixed elevation, which is defined in XML. The second view, the square, 69changes its elevation using [setTranslationZ()][1] when a user touches it: 70 71 shape2.setOnTouchListener(new View.OnTouchListener() { 72 @Override 73 public boolean onTouch(View view, MotionEvent motionEvent) { 74 int action = motionEvent.getActionMasked(); 75 /* Raise view on ACTION_DOWN and lower it on ACTION_UP. */ 76 switch (action) { 77 case MotionEvent.ACTION_DOWN: 78 Log.d(TAG, "ACTION_DOWN on view."); 79 view.setTranslationZ(120); 80 break; 81 case MotionEvent.ACTION_UP: 82 Log.d(TAG, "ACTION_UP on view."); 83 view.setTranslationZ(0); 84 break; 85 default: 86 return false; 87 } 88 return true; 89 } 90 }); 91 92The elevation reverts back once the touch is removed. 93 94[1]: https://developer.android.com/training/material/shadows-clipping.html#Elevation 95]]> 96 </intro> 97 </metadata> 98</sample> 99