Home | History | Annotate | Download | only in ClippingBasic
      1 <?xml version="1.0" encoding="UTF-8"?>
      2 <!--
      3  Copyright 2013 The Android Open Source Project
      4 
      5  Licensed under the Apache License, Version 2.0 (the "License");
      6  you may not use this file except in compliance with the License.
      7  You may obtain a copy of the License at
      8 
      9      http://www.apache.org/licenses/LICENSE-2.0
     10 
     11  Unless required by applicable law or agreed to in writing, software
     12  distributed under the License is distributed on an "AS IS" BASIS,
     13  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  See the License for the specific language governing permissions and
     15  limitations under the License.
     16 -->
     17 
     18 
     19 
     20 <sample>
     21     <name>ClippingBasic</name>
     22     <group>UI</group>
     23     <package>com.example.android.clippingbasic</package>
     24 
     25     <minSdk>21</minSdk>
     26 
     27     <strings>
     28         <intro>
     29             <![CDATA[
     30             Basic sample to demonstrate clipping on a View.
     31             ]]>
     32         </intro>
     33     </strings>
     34 
     35     <template src="base"/>
     36     <template src="FragmentView"/>
     37     <common src="logger"/>
     38     <common src="activities"/>
     39 
     40     <metadata>
     41         <status>PUBLISHED</status>
     42         <categories>UI Views</categories>
     43         <technologies>Android</technologies>
     44         <languages>Java</languages>
     45         <solutions>Mobile</solutions>
     46         <level>BEGINNER</level>
     47         <icon>screenshots/web-icon.png</icon>
     48         <screenshots>
     49             <img>screenshots/screenshot-1.png</img>
     50             <img>screenshots/screenshot-2.png</img>
     51         </screenshots>
     52         <api_refs>
     53             <android>android.view.ViewOutlineProvider</android>
     54         </api_refs>
     55 
     56         <description>
     57 <![CDATA[
     58 A basic app showing how to clip on a View using [ViewOutlineProvider][1] interface,
     59 by which a View builds its outline, used for shadowing and clipping.
     60 ]]>
     61         </description>
     62 
     63         <intro>
     64 <![CDATA[
     65 The [ViewOutlineProvider][1] interface offers you a method to populate the outline of a View.
     66 You need to implement a getOutline(android.view.View, android.graphics.Outline)
     67 method to clip a View in a specific shape.
     68 
     69 This example clips the outline of a View as a rounded rectangle by defining a class that
     70  implements ViewOutlineProvider by following code:
     71 
     72 ```java
     73 private class ClipOutlineProvider extends ViewOutlineProvider {
     74     @Override
     75     public void getOutline(View view, Outline outline) {
     76         final int margin = Math.min(view.getWidth(), view.getHeight()) / 10;
     77         outline.setRoundRect(margin, margin, view.getWidth() - margin,
     78                 view.getHeight() - margin, margin / 2);
     79     }
     80 }
     81 ```
     82 
     83 To clip a View by the defined outline, setting a OutlineProvider to a View
     84 to be clipped is needed like following:
     85 
     86 ```java
     87 final View clippedView = view.findViewById(R.id.frame);
     88 clippedView.setOutlineProvider(mOutlineProvider);
     89 ```
     90 
     91 You can toggle if the View is clipped by calling [setClipToOutline(boolean)][2]
     92 like following code:
     93 
     94 ```java
     95 clippedView.setClipToOutline(true); // Setting false disable clipping
     96 ```
     97 
     98 [1]: https://developer.android.com/reference/android/view/ViewOutlineProvider.html
     99 [2]: https://developer.android.com/reference/android/view/View.html#setClipToOutline(boolean)
    100 ]]>
    101         </intro>
    102     </metadata>
    103 </sample>
    104