0
標高を持ち、白い背景描画可能なカスタムビューを作成しました。 xmlから呼び出すと、xmlエディタで正しく表示されますが、私がMarshmallowデバイスで実行すると、標高と白の背景が全くありません。カスタムビュー拡張RelativeLayoutが正しく表示されない
public class ElevatedRelativeLayout extends RelativeLayout {
private Context context;
public int ELEVATION = 10;
public ElevatedRelativeLayout(Context context){
super(context);
this.context = context;
setAttributes();
}
public ElevatedRelativeLayout(Context context, AttributeSet attrs) {
super(context, attrs);
this.context = context;
setAttributes();
}
public ElevatedRelativeLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
this.context = context;
setAttributes();
}
private void setAttributes(){
if(Build.VERSION.SDK_INT>=21)
this.setElevation(ELEVATION);
this.setBackgroundDrawable(new CornerShapedDrawable(context, Color.WHITE , GradientDrawable.RECTANGLE, 30));
}}
CornerShapedDrawable:
public class CornerShapedDrawable extends Drawable {
int type = 0 ;
float corners = 0 ;
int backgroundColor;
public CornerShapedDrawable (Context context , int backgroundColor ,int type , float corners){
this.type = type;
this.corners = corners;
this.backgroundColor = backgroundColor;
}
@Override
public void draw(Canvas canvas) {
float[] f = new float[]{corners,corners,corners,corners,0,0,0,0};
GradientDrawable shape = new GradientDrawable();
shape.setCornerRadii(f);
shape.setShape(type);
shape.setColor(backgroundColor);
shape.setStroke(3 , Color.WHITE);
}}
問題はここで何ですか?私はonDrawメソッドをオーバーライドしようとしましたが、役に立たなかった。