Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/194.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android ColorDrawable不会在其边界上绘制_Android_Android Layout - Fatal编程技术网

Android ColorDrawable不会在其边界上绘制

Android ColorDrawable不会在其边界上绘制,android,android-layout,Android,Android Layout,我正在尝试将ColorDrawable设置为backgroundDrawable可查看的边界,但它无法正常工作,请使用以下代码: ColorDrawable d = new ColorDrawable(getContext().getResources() .getColor(R.color.red)); d.setBounds(0, 0, 20, 20); convertView.setBackgroundDrawable(d); 结果是convertView背景在此处被红

我正在尝试将ColorDrawable设置为backgroundDrawable可查看的边界,但它无法正常工作,请使用以下代码:

ColorDrawable d = new ColorDrawable(getContext().getResources()
        .getColor(R.color.red));
d.setBounds(0, 0, 20, 20);

convertView.setBackgroundDrawable(d);
结果是convertView背景在此处被红色填充


谢谢。

好的,所以当使用可绘制作为视图背景时,视图的边界会随着视图的布局而改变。因此,有了严格的界限,我需要扩展Drawable,并为其界限使用私有Rect。

您的具体要求是什么?