diff options
Diffstat (limited to 'ui/views/Elevation/ElevationBasic/README.md')
-rw-r--r-- | ui/views/Elevation/ElevationBasic/README.md | 52 |
1 files changed, 45 insertions, 7 deletions
diff --git a/ui/views/Elevation/ElevationBasic/README.md b/ui/views/Elevation/ElevationBasic/README.md index b40a734f..f3cab116 100644 --- a/ui/views/Elevation/ElevationBasic/README.md +++ b/ui/views/Elevation/ElevationBasic/README.md @@ -1,17 +1,55 @@ + Android ElevationBasic Sample -============================== +=================================== + +This sample demonstrates ways to move a view in the z-axis using +`setTranslationZ()`. This method was introduced in API Level 21 ('Lollipop'). + +Introduction +------------ + +This sample uses two shapes, a circle and a square, and it demonstrates two +alternative ways to move a view in the z-axis. The first shape, the circle, +has a fixed elevation, which is defined in XML. The second view, the square, +changes its elevation using [setTranslationZ()][1] when a user touches it: -This sample demonstrates two alternative ways to move a view in the z-axis. The -first view has a fixed elevation using XML and the second one is raised when the user -taps on it, using setTranslationZ(). + shape2.setOnTouchListener(new View.OnTouchListener() { + @Override + public boolean onTouch(View view, MotionEvent motionEvent) { + int action = motionEvent.getActionMasked(); + /* Raise view on ACTION_DOWN and lower it on ACTION_UP. */ + switch (action) { + case MotionEvent.ACTION_DOWN: + Log.d(TAG, "ACTION_DOWN on view."); + view.setTranslationZ(120); + break; + case MotionEvent.ACTION_UP: + Log.d(TAG, "ACTION_UP on view."); + view.setTranslationZ(0); + break; + default: + return false; + } + return true; + } + }); + +The elevation reverts back once the touch is removed. + +[1]: https://developer.android.com/training/material/shadows-clipping.html#Elevation Pre-requisites -------------- -- Android SDK (L Developer Preview) -- Android Build Tools v20 +- Android SDK v21 +- Android Build Tools v22.0.1 - Android Support Repository +Screenshots +------------- + +<img src="screenshots/fixed.png" height="400" alt="Screenshot"/> <img src="screenshots/raised.png" height="400" alt="Screenshot"/> + Getting Started --------------- @@ -42,7 +80,7 @@ file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 +http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |