0
我使用包含兩個元素的複雜背景製作自定義視圖:位於頂部 - 位圖可繪製和波紋管9路徑可繪製。Android在畫布頂部繪製9路徑繪製而不是指定位置
我的代碼是:
public class MyCustomFrame extends FrameLayout
{
Drawable main, top;
public RequestInfoBottomContainer(Context context, AttributeSet attrs, int defStyle)
{
super(context, attrs, defStyle);
main = res.getDrawable(R.drawable.bg_main);
top = res.getDrawable(R.drawable.bg_top);
}
@Override
protected void onDraw(Canvas canvas)
{
int width = getMeasuredWidth();
int height = canvas.getHeight();
top.setBounds(0, 0, width, top.getIntrinsicHeight());
main.setBounds(0, top.getIntrinsicHeight(), width, height);
top.draw(canvas);
main.draw(canvas);
}
}
例如,如果頂部可繪高度爲10像素,寬度爲500像素,高200像素和予置範圍0,10,500,200到主可繪製的Android平它是0,0,500,200邊界。即主要吸引頂部。
我做錯了什麼?
'top.getIntrinsicHeight()'可能返回0.您可以檢查嗎? – Vikram
它總是返回值> 0.在我的情況下,值是10。 – Nik