话不多说上图
实现简单利用了这个ClipDrawable
clip.xml
<?xml version="1.0" encoding="utf-8"?> <clip xmlns:android="http://schemas.android.com/apk/res/android" android:drawable="@drawable/ic" android:clipOrientation="horizontal" android:gravity="left">
activity_main.xml
<ImageView android:id="@+id/imgclip" android:layout_width="200dp" android:layout_height="200dp" android:src="@drawable/clip"/>
MainActivity.java
package mdm.study.com.myresoucestudy; import android.graphics.drawable.ClipDrawable; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.support.v7.app.AppCompatActivity; import android.widget.ImageView; import java.util.Timer; import java.util.TimerTask; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //徐徐展开的风景 ImageView imgClip = (ImageView) findViewById(R.id.imgclip); final ClipDrawable clipDrawable = (ClipDrawable) imgClip.getDrawable(); final Handler handler = new Handler(){ @Override public void handleMessage(Message msg) { if(msg.what == 0x123){ //clipDrawable值的范围0! 10000 clipDrawable.setLevel(clipDrawable.getLevel() + 50); } } }; final Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { Message msg = Message.obtain(); msg.what = 0x123; handler.sendMessage(msg); //取消定时器 if(clipDrawable.getLevel() >= 10000){ timer.cancel(); } } },0,10); } }
简单吧。
时间: 2024-11-02 12:20:20