ClipDrawable的使用
2016-04-24 14:33
309 查看
ClipDrawable的使用
ClipDrawable对应于标签,他可以根据自己当前的等级(level)来裁剪另一个drawable。裁剪的方向可以通过android:clipOrientation和android:gravity属性来共同控制。
例子:
1.在clip_drawable.xml文件中
2.在activity_main.xml文件中
3.在MainActivity文件中
ClipDrawable对应于标签,他可以根据自己当前的等级(level)来裁剪另一个drawable。裁剪的方向可以通过android:clipOrientation和android:gravity属性来共同控制。
例子:
1.在clip_drawable.xml文件中
<?xml version="1.0" encoding="utf-8"?> <clip xmlns:android="http://schemas.android.com/apk/res/android" android:drawable="@mipmap/ic_launcher" android:clipOrientation="vertical" android:gravity="top"> <!--clipOrientation:有水平和竖直方向--> <!--gravity:属性比较多。top,bottom,left,right,center,center_vertical,center_horizontal等。--> </clip>
2.在activity_main.xml文件中
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="www.yundo.com.drawable.MainActivity"> <ImageView android:id="@+id/iv" android:src="@drawable/clip_drawable" android:background="@color/red" android:layout_width="match_parent" android:layout_height="200dp" /> </RelativeLayout>
3.在MainActivity文件中
public class MainActivity extends AppCompatActivity { private ImageView mImageView; private boolean isBlueToRed; private TransitionDrawable tranBackground; private ClipDrawable clipBackground; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mImageView = (ImageView) findViewById(R.id.iv); clipBackground = (ClipDrawable) mImageView.getDrawable(); mImageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { clip(); } }); } private void clip() { //level在0-10000之间,0表示完全裁剪,10000表示完全不裁剪。设置的值越大,裁剪的范围就越小。 clipBackground.setLevel(5000); } }
相关文章推荐
- 二叉排序树
- Android中的MediaMetadataRetriever类取得媒体文件信息
- 【Arduino官方教程第一辑】示例程序 2-6 音乐键盘-tone函数的运用
- 利用AppInventor实现登录功能(完整版)
- NAT 四种地址解释
- 轮播图插件myFocus使用
- php 封装mysql 数据库操作类
- Linux内核学习总结
- 利用AppInventor实现注册功能(完整版)
- JS中的this、apply、call
- java 图片缩略图的两种方法
- 【POJ1082】Calendar Game (博弈)
- 基于ThinkPHP3的微信平台开发_1
- myeclipse2015ci最高只适应spring3.1
- 格式化时遇到的问题
- 自学的android,写了一个很简单的计算器。
- c中断函数
- SAE中创建数据表
- Android ListView中Item点击事件失效解决方案
- Struts项目目录及注意点