2016-04-04 17 views
0

Bir yükseltmesi olan ve beyaz bir arka plan çizilebilir kullanan özel bir görünüm oluşturdum. Onu xml'den çağırdığımda, xml editöründe doğru bir şekilde gösteriliyor, ancak Marshmallow cihazımda çalıştırdığımda, hiçbir yükseklik ve beyaz arka plan yok.CustomView genişletme RelativeLayout doğru şekilde gösterilmiyor

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); 
}} 

sorun burada ne var? OnDraw yöntemini geçersiz kılmayı denedim ama boşuna.

cevap

0

Sanırım özel RelativeLayout, ana sınırlarından dolayı görünümünüzün gölgesini çizemiyor. Belki

ebeveyn düzeninde bu koymak için deneyin:

android:clipToPadding="false" 
İlgili konular