Home | History | Annotate | only in /developers/samples/android/ui/views/Clipping/ClippingBasic
Up to higher level directory
NameDateSize
Application/21-Oct-2016
build.gradle21-Oct-2016272
buildSrc/21-Oct-2016
CONTRIB.md21-Oct-20161.6K
gradle/21-Oct-2016
gradlew21-Oct-20165K
gradlew.bat21-Oct-20162.3K
LICENSE21-Oct-201631.5K
packaging.yaml21-Oct-2016474
README.md21-Oct-20163.2K
screenshots/21-Oct-2016
settings.gradle21-Oct-201622
template-params.xml21-Oct-20163.1K

README.md

      1 
      2 Android ClippingBasic Sample
      3 ===================================
      4 
      5 A basic app showing how to clip on a View using [ViewOutlineProvider][1] interface,
      6 by which a View builds its outline, used for shadowing and clipping.
      7 
      8 Introduction
      9 ------------
     10 
     11 The [ViewOutlineProvider][1] interface offers you a method to populate the outline of a View.
     12 You need to implement a getOutline(android.view.View, android.graphics.Outline)
     13 method to clip a View in a specific shape.
     14 
     15 This example clips the outline of a View as a rounded rectangle by defining a class that
     16  implements ViewOutlineProvider by following code:
     17 
     18 ```java
     19 private class ClipOutlineProvider extends ViewOutlineProvider {
     20     @Override
     21     public void getOutline(View view, Outline outline) {
     22         final int margin = Math.min(view.getWidth(), view.getHeight()) / 10;
     23         outline.setRoundRect(margin, margin, view.getWidth() - margin,
     24                 view.getHeight() - margin, margin / 2);
     25     }
     26 }
     27 ```
     28 
     29 To clip a View by the defined outline, setting a OutlineProvider to a View
     30 to be clipped is needed like following:
     31 
     32 ```java
     33 final View clippedView = view.findViewById(R.id.frame);
     34 clippedView.setOutlineProvider(mOutlineProvider);
     35 ```
     36 
     37 You can toggle if the View is clipped by calling [setClipToOutline(boolean)][2]
     38 like following code:
     39 
     40 ```java
     41 clippedView.setClipToOutline(true); // Setting false disable clipping
     42 ```
     43 
     44 [1]: https://developer.android.com/reference/android/view/ViewOutlineProvider.html
     45 [2]: https://developer.android.com/reference/android/view/View.html#setClipToOutline(boolean)
     46 
     47 Pre-requisites
     48 --------------
     49 
     50 - Android SDK 24
     51 - Android Build Tools v24.0.1
     52 - Android Support Repository
     53 
     54 Screenshots
     55 -------------
     56 
     57 <img src="screenshots/screenshot-1.png" height="400" alt="Screenshot"/> <img src="screenshots/screenshot-2.png" height="400" alt="Screenshot"/> 
     58 
     59 Getting Started
     60 ---------------
     61 
     62 This sample uses the Gradle build system. To build this project, use the
     63 "gradlew build" command or use "Import Project" in Android Studio.
     64 
     65 Support
     66 -------
     67 
     68 - Google+ Community: https://plus.google.com/communities/105153134372062985968
     69 - Stack Overflow: http://stackoverflow.com/questions/tagged/android
     70 
     71 If you've found an error in this sample, please file an issue:
     72 https://github.com/googlesamples/android-ClippingBasic
     73 
     74 Patches are encouraged, and may be submitted by forking this project and
     75 submitting a pull request through GitHub. Please see CONTRIBUTING.md for more details.
     76 
     77 License
     78 -------
     79 
     80 Copyright 2016 The Android Open Source Project, Inc.
     81 
     82 Licensed to the Apache Software Foundation (ASF) under one or more contributor
     83 license agreements.  See the NOTICE file distributed with this work for
     84 additional information regarding copyright ownership.  The ASF licenses this
     85 file to you under the Apache License, Version 2.0 (the "License"); you may not
     86 use this file except in compliance with the License.  You may obtain a copy of
     87 the License at
     88 
     89 http://www.apache.org/licenses/LICENSE-2.0
     90 
     91 Unless required by applicable law or agreed to in writing, software
     92 distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
     93 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
     94 License for the specific language governing permissions and limitations under
     95 the License.
     96