1

我正在尝试学习如何在 Android 画布上绘图。这段代码似乎有效并且可以编译,但我没有得到我的形状。

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ShapeDrawable shape = new ShapeDrawable(new ArcShape(0, 250));
        shape.setIntrinsicHeight(100);
        shape.setIntrinsicWidth(100);
        shape.getPaint().setColor(Color.RED);
        Canvas canvas = new Canvas();
        shape.draw(canvas);

    }
}

我正在尝试按照这里的教程:http: //kirill-poletaev.blogspot.com/2013/02/android-beginner-tutorial-part-90-path.html

4

1 回答 1

1

ShapeDrawable例如,您可以将对象Drawable设置为视图背景。你可以做这样的事情。-

ImageView yourImage = (ImageView) findViewById(R.id.yourImageId);
yourImage.setImageDrawable(shape);
于 2013-10-14T21:09:49.630 回答