android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/my_image"/>
___________________________________________________________
从XML文件中创建
保存上面的文件为res/drawable/expand_collapse.xml,下面的代码去实例化一个TransitionDrawable,并
把它设置为ImageView的内容
Resources res = mContext.getResources() ;
TransitionDrawable transition = (TransitionDrawable)
res.getDrawable(R.drawable.expand_collapse);
ImageView image = (ImageView) findViewById(R.id.toggle_image);
image.setImageDrawable(transition);
接着,这个函数可以让它允许1分钟。
transition.startTransition(1000);
参考Drawable类列表可以得到更多所支持的XML属性。
(2) ShapeDrawable
public class CustomDrawableView extends View {
private ShapeDrawable mDrawable;
public CustomDrawableView(Context context) {
super(context);
int x = 10;
int y = 10;
int width = 300;
int height = 50;
mDrawable = new ShapeDrawable(new OvalShape());
mDrawable.getPaint().setColor(0xff74AC23);
mDrawable.setBounds(x, y, x + width, y + height);
}
protected void onDraw(Canvas canvas) {
mDrawable.draw(canvas);
}
}
(3) NinePatchDrawable
(4) Tween Animation
(5) Frame Animation
5 3D and OpenGL
(1) GLSurfaceView
class A implements GLSurfaceView.Renderer {
//SurfaceView创建时响应
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
}
//SurfaceView变化时响应
public void onSurfaceChanged(GL10 gl, int w, int h) {
gl.glViewport(0, 0, w, h);
}
//SurfaceView显示时响应
public void onDrawFrame(GL10 gl) {
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
}
}