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