一、效果图送上:
二、xml布局文件:
<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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:src="@drawable/bg"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="12dip"
android:src="@drawable/clip"
android:id="@+id/image"
/>
<Button
android:id="@+id/switchImg"
android:onClick="switchImg"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello_world"
android:textSize="20sp"
android:layout_marginTop="320dip"
/>
</RelativeLayout>
三、实现代码:
package com.example.layerlist;
import android.os.Bundle;
import android.app.Activity;
import android.graphics.drawable.ClipDrawable;
import android.view.Menu;
import android.view.View;
import android.widget.ImageView;
public class MainActivity extends Activity {
private ImageView image;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
image = (ImageView)findViewById(R.id.image);
}
/**
* 切换图片
* @param v
*/
public void switchImg(View v){
ClipDrawable drawable = (ClipDrawable)image.getDrawable();
drawable.setLevel(drawable.getLevel()+1200);
}
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
详情见源码:
http://download.csdn.net/detail/u010885095/8240835