【发布时间】:2015-08-09 10:36:30
【问题描述】:
我想创建一个带有弧形背景的视图..我的视图的权重为 .3.. 这使它占据了我布局的三分之一..
我尝试将其背景设置为弧形(我希望它是半椭圆形),如下所示:
ArcShape shape = new ArcShape(270, 180);
ShapeDrawable shapeDrawable = new ShapeDrawable(shape);
shapeDrawable.getPaint().setColor(getResources().getColor(R.color.primary_color));
leftPathView.setBackgroundDrawable(shapeDrawable);
这会生成我需要的形状,但它并没有填满我的视图空间。它只需要它的一半。但是当我创建一个完整的圆圈时,它会占据所有空间。
有什么想法吗?
【问题讨论】:
-
避免使用恒定像素值 (
270, 180)。使用 View.getWith() 和 View.getHeight() 在运行时计算值 -
这些是圆弧的角度.. 看看构造函数:developer.android.com/reference/android/graphics/drawable/…
-
我的错,所以也许你应该使用调整大小的方法:developer.android.com/reference/android/graphics/drawable/…, float)
标签: java android xml android-shape