实现屏幕的渐渐展开
main.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <ImageView android:id="@+id/imageView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_marginTop="34dp" android:src="@drawable/gameclip" /> </RelativeLayout>
MainActivity.java
package lesson.my.sudoku; import java.util.Timer; import java.util.TimerTask; import lession.my.sudoku.R; import android.app.Activity; import android.graphics.drawable.ClipDrawable; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.widget.ImageView; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ImageView imageview = (ImageView) findViewById(R.id.imageView2); final ClipDrawable drawable = (ClipDrawable) imageview.getDrawable(); drawable.setLevel(0); final Handler handler = new Handler() { //handler类用于与子线程的通信 public void handleMessage(Message msg) { if (msg.what == 0x1233) { //每当受到子线程的信息,就让drawable变化 drawable.setLevel(drawable.getLevel() + 200); } } }; final Timer timer = new Timer();//timer计时器,休眠300ms timer.schedule(new TimerTask() { public void run() { Message msg = new Message(); msg.what = 0x1233; handler.sendMessage(msg); if (drawable.getLevel() >= 10000) { timer.cancel(); } } }, 0, 300); } }