Ich versuche, eine Ansicht zu erstellen, die alle den verfügbaren Platz auf dem Bildschirm füllen. Iv'e stellte meine Ansicht Layout params match_parent
und verwendet getHeight()
und getWidth()
wenn zog Rect
auf Canvas
und es füllt sich immer noch nur etwa zwei Drittel des Bildschirms.Custom füllt nicht verfügbar Raum
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:beat_box="http://schemas.android.com/tools">
<com.yotam.aprivate.demo.mybeatbox.Views.BeatBox
android:layout_width="match_parent"
android:layout_height="match_parent"
beat_box:my_color="5D32EA">
</com.yotam.aprivate.demo.mybeatbox.Views.BeatBox>
</RelativeLayout>
Custom:
public class BeatBox extends View {
private int color;
private Context context;
private Paint paintBox = new Paint();
private Paint paintBackground = new Paint();
public BeatBox(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
this.context = context;
color = getAttrColor(attrs);
initDrawing();
}
@Override
protected void onDraw(Canvas canvas) {
canvas.drawRect(0,0,canvas.getHeight(), canvas.getWidth(), paintBackground); //this.getHeight() this.getWidth() also doesn't work
paintBackground.setShader(new LinearGradient(0, 0, getWidth() , getHeight(), Color.parseColor("#cb356b"), Color.parseColor("#bd3f32"), Shader.TileMode.MIRROR));
super.onDraw(canvas);
}