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