| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.android.test.hwui; |
| 18 |
|
| 19 |
import android.app.Activity; |
| 20 |
import android.content.Context; |
| 21 |
import android.graphics.Canvas; |
| 22 |
import android.graphics.Paint; |
| 23 |
import android.os.Bundle; |
| 24 |
import android.view.View; |
| 25 |
import android.widget.LinearLayout; |
| 26 |
|
| 27 |
@SuppressWarnings("UnusedDeclaration") |
| 28 |
public class MultiLayersActivity extends Activity { |
| 29 |
@Override |
| 30 |
protected void onCreate(Bundle savedInstanceState) { |
| 31 |
super.onCreate(savedInstanceState); |
| 32 |
|
| 33 |
LinearLayout grid = new LinearLayout(this); |
| 34 |
grid.setOrientation(LinearLayout.VERTICAL); |
| 35 |
|
| 36 |
LinearLayout row1 = new LinearLayout(this); |
| 37 |
row1.setOrientation(LinearLayout.HORIZONTAL); |
| 38 |
grid.addView(row1, new LinearLayout.LayoutParams( |
| 39 |
LinearLayout.LayoutParams.MATCH_PARENT, 0, 1.0f)); |
| 40 |
|
| 41 |
LinearLayout row2 = new LinearLayout(this); |
| 42 |
row2.setOrientation(LinearLayout.HORIZONTAL); |
| 43 |
grid.addView(row2, new LinearLayout.LayoutParams( |
| 44 |
LinearLayout.LayoutParams.MATCH_PARENT, 0, 1.0f)); |
| 45 |
|
| 46 |
row1.addView(new LayerView(this, 0xffff0000), new LinearLayout.LayoutParams( |
| 47 |
0, LinearLayout.LayoutParams.MATCH_PARENT, 1.0f)); |
| 48 |
row1.addView(new LayerView(this, 0x0f00ff00), new LinearLayout.LayoutParams( |
| 49 |
0, LinearLayout.LayoutParams.MATCH_PARENT, 1.0f)); |
| 50 |
|
| 51 |
row2.addView(new LayerView(this, 0x0f0000ff), new LinearLayout.LayoutParams( |
| 52 |
0, LinearLayout.LayoutParams.MATCH_PARENT, 1.0f)); |
| 53 |
row2.addView(new LayerView(this, 0xffffff00), new LinearLayout.LayoutParams( |
| 54 |
0, LinearLayout.LayoutParams.MATCH_PARENT, 1.0f)); |
| 55 |
|
| 56 |
setContentView(grid); |
| 57 |
} |
| 58 |
|
| 59 |
private class LayerView extends View { |
| 60 |
private final Paint mPaint; |
| 61 |
|
| 62 |
public LayerView(Context context, int color) { |
| 63 |
super(context); |
| 64 |
mPaint = new Paint(); |
| 65 |
mPaint.setColor(color); |
| 66 |
setLayerType(LAYER_TYPE_HARDWARE, null); |
| 67 |
} |
| 68 |
|
| 69 |
@Override |
| 70 |
protected void onDraw(Canvas canvas) { |
| 71 |
canvas.drawRect(0.0f, 0.0f, getWidth(), getHeight(), mPaint); |
| 72 |
invalidate(); |
| 73 |
} |
| 74 |
} |
| 75 |
} |