18 Ui美化 剪切动画clip
- 输入0 - 10000 让图片根据数值显示部分图片
在工程文件的res/drawable/新建clip文件
<?xml version="1.0" encoding="utf-8"?> <clip xmlns:android="http://schemas.android.com/apk/res/android" android:clipOrientation="horizontal" android:drawable="@drawable/android1" android:gravity="left" > <!-- android:clipOrientation="horizontal"剪切方向 android:drawable="@drawable/android1"设置图片源 android:gravity="left"剪切从哪里开始 --> </clip>
使用
package com.fmy.lianxi;
import android.R.transition;
import android.app.Activity;
import android.graphics.drawable.ClipDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.TransitionDrawable;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;
public class MainActivity extends Activity {
private ImageView iv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iv = (ImageView) findViewById(R.id.iv);
}
public void click(View v) {
ClipDrawable drawable = (ClipDrawable) iv.getDrawable();
// level 0 - 10000 之间 大于等于10000显示完全 小于等于0完全不显示
int level = drawable.getLevel();
drawable.setLevel(level+10000);
}
}
- 布局文件
<LinearLayout 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"
android:orientation="vertical" >
<ImageView
android:id="@+id/iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/myclip" />
</LinearLayout>