[英]Android - Canvas Doesn't Show
I have researched this on Stack Overflow, but I didn't find the fix to my problem. 我已经在Stack Overflow上对此进行了研究,但没有找到解决问题的方法。 I have a view that contains the code for a vertical, yellow line on the screen.
我有一个视图,其中包含屏幕上垂直的黄线的代码。 I have an activity that creates the dialog whose content view is an instance of the view.
我有一个活动来创建对话框,该对话框的内容视图是该视图的实例。 The dialog pops up, but the yellow line doesn't show.
对话框弹出,但不显示黄线。 What am I missing?
我想念什么? Here is my code:
这是我的代码:
View : 查看 :
public guidelines(Context context) {
super(context);
int x = this.getWidth()/2 - 3;
int y = this.getHeight();
shape = new ShapeDrawable(new RectShape());
shape.getPaint().setColor(Color.YELLOW);
shape.setBounds(x, 0, x+6, y);
}
@Override
protected void onDraw(Canvas canvas) {
shape.draw(canvas);
}
Layout for the View : 视图的布局 :
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/---
android:layout_width="match_parent" android:layout_height="match_parent">
<!-- <--- android:background="#ccc"
android:layout_width="300dp" android:layout_height="300dp" android:paddingLeft="20dp"
android:paddingBottom="40dp" app:exampleDimension="24sp" app:exampleColor="#33b5e5"
app:exampleString="Hello, guidelines" /> -->
< ---
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/frame"/>
</FrameLayout>
Dialog Calling Code : 对话框调用代码 :
final Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
guidelines g = new guidelines(this);
dialog.setContentView(g);
dialog.show();
Thanks. 谢谢。
It was better to just use the drawRect
function of the canvas. 最好只使用画布的
drawRect
函数。 I did that and it worked. 我做到了,它奏效了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.