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