ビューを拡張してカスタム ウィジェットを作成しました。独立したピクセル単位でウィジェットの高さを定義したいと思います。ピクセル密度に目的の高さを掛けることでできると思いますが、その方法がわかりません。
私がこれまでに持っているもの(最小化):
public class Timeline extends View
{
@Override
protected void onDraw(Canvas canvas) {
//super.onDraw(canvas);
int canvasWidth = canvas.getWidth();
this.widgetWith = canvasWidth;
this.setBackgroundGradientNoVideo();
RectF rect = new RectF();
rect.set(0, 0, canvasWidth, 50);
//Dessin d'un rectangle de fond
canvas.drawRoundRect(rect, 10, 10, this.paint);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// TODO Auto-generated method stub
//super.onMeasure(widthMeasureSpec, 50);
this.setMeasuredDimension(widthMeasureSpec, 50);
this.widgetWith = MeasureSpec.getSize(widthMeasureSpec);
}
}
だから私は行を変更したい
this.setMeasuredDimension(widthMeasureSpec, 50);
と
rect.set(0, 0, canvasWidth, 50);
ピクセルに依存しないものに。
ありがとう