android-为什么ImageView画布是黑色的?
我是android graphic的新手,所以抓紧你的帽子! 无论我做什么,屏幕都是黑色的。 我画了一个圆,我画了位图,并注意显示。 这是xml、代码和显示我的屏幕的图片。 我想我必须设置ImageView的大小,也许这就是为什么它是黑色的 R.layout.main 1android-为什么ImageView画布是黑色的?,android,canvas,imageview,Android,Canvas,Imageview,我是android graphic的新手,所以抓紧你的帽子! 无论我做什么,屏幕都是黑色的。 我画了一个圆,我画了位图,并注意显示。 这是xml、代码和显示我的屏幕的图片。 我想我必须设置ImageView的大小,也许这就是为什么它是黑色的 R.layout.main 1 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.hasse.move.DrawView
android:id="@+id/mainView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#00FF00"
android:adjustViewBounds="true"
/>
<RelativeLayout
android:id="@+id/InnerRelativeLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<EditText
android:id="@+id/edittextaddtext"
android:layout_width="fill_parent"
android:layout_toLeftOf="@+id/btnsave"
android:layout_height="wrap_content"
android:text="wrap"
/>
<Button
android:id="@+id/btnsave"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="save"
/>
</RelativeLayout>
</RelativeLayout>
}
主要活动
public class Main extends Activity {
DrawView theImage;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
// draw the view
setContentView(R.layout.main1);
theImage = (DrawView) findViewById(R.id.mainView);
//do stuff
}
@Override
public void onConfigurationChanged(Configuration newConfig)
{
// Toast.makeText(this, "onConfigurationChanged",Toast.LENGTH_LONG).show();
super.onConfigurationChanged(newConfig);
}
}
形象
查看您的代码,您不太可能在尝试使用空绘制对象绘制圆时看到圆。要测试代码,请确保使用与背景颜色形成对比的颜色绘制对象。其次,我将调用超级对象方法,例如
super.onDraw(canvas);
我不能100%确定是否使用空绘制对象绘制位图。
另外,检查布局文件中DrawView类(com.hasse.move.DrawView)的包名是否与实际DrawView类的包名匹配。两条注释:1)背景色为0x00FF00,这意味着alpha(不透明)为零。如果你想背景是绿色的,把背景颜色设置为0xFF00FF00。我有点像这样工作。在构造函数中,我正在运行…setImageBitmap(btm)。在onDraw im运行中…canvas.drawBitmap(位图,0,0,null);。这很奇怪,但似乎我必须在构造函数中运行该行,就像启动imageView(dunno)一样。但我有两张图片,一张居中,另一张位于0,0。这是一张图片视图,不是画布。我之所以提起它,是因为我认为你的字面意思是画布,并开始在脑海中回答这个问题,直到我发现它不是。是的,很抱歉,但我在imageView的画布上绘制。我更新问题标题!谢谢大家!让它工作起来,明天将发布答案。这里有一个新的跟进问题,谢谢我添加了super.onDraw(canvas);
super.onDraw(canvas);