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