我正在尝试学习在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
答案 0 :(得分:1)
ShapeDrawable
对象是Drawable
,您可以将其设置为视图背景。你可以这样做.-
ImageView yourImage = (ImageView) findViewById(R.id.yourImageId);
yourImage.setImageDrawable(shape);