Add DEV4.5/exo2_controle
This commit is contained in:
40
DEV4.5/exo2_controle
Normal file
40
DEV4.5/exo2_controle
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
package com.example.partition;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.Paint;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
public class QuadratureView extends View {
|
||||||
|
private Paint paint;
|
||||||
|
private int color;
|
||||||
|
|
||||||
|
public QuadratureView(Context context, AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
paint = new Paint();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setColor(int color) {
|
||||||
|
this.color = color;
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onDraw(Canvas canvas) {
|
||||||
|
super.onDraw(canvas);
|
||||||
|
paint.setColor(color);
|
||||||
|
canvas.drawRect(0, 0, getWidth(), getHeight(), paint);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Modifications dans activity_main.xml (remplacement des <View> par <com.example.partition.QuadratureView>)
|
||||||
|
|
||||||
|
<com.example.partition.QuadratureView
|
||||||
|
android:layout_width="100dp"
|
||||||
|
android:layout_height="100dp"
|
||||||
|
android:layout_alignParentTop="true"
|
||||||
|
android:layout_alignParentStart="true"
|
||||||
|
android:background="#AACCEE"/>
|
||||||
|
|
||||||
|
(Faire de même pour les autres View)
|
||||||
Reference in New Issue
Block a user