更改circle_layoutinnerrelativelayout的声明以指定以dp为单位的高度而不是wrap_content并去掉marginTop:
<RelativeLayout
android:id="@+id/circle_layoutinner"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_above="@+id/rating_viewtv"
android:layout_alignParentTop="true"
android:background="@drawable/circle_inset_drawable"
android:layout_centerHorizontal="true" >
定义circle_inset_drawable.xml以将橙色圆圈偏移正确的量:
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/circletwo"
android:insetTop="20dp"
android:visible="true" />
insetTop应该是circle_layout的高度减去circle_layoutinner的高度
您可以在代码中设置可绘制对象的颜色,如下所示。您只需要从布局对象开始,然后继续深入浏览对象,直到找到允许您设置颜色的对象:
RelativeLayout rl = (RelativeLayout)findViewById(R.id.circle_layoutinner);
InsetDrawable id = (InsetDrawable)rl.getBackground();
GradientDrawable gd = (GradientDrawable)id.getDrawable(); // API 19+ only!
gd.setColor(0xffff0000); // set to red
或者您可以在代码中创建 InsetDrawable,如下所示:
RelativeLayout rl = (RelativeLayout)findViewById(R.id.circle_layoutinner);
GradientDrawable gd = (GradientDrawable)getResources().getDrawable( R.drawable.circletwo );
gd.setColor(0xffff0000); // set to red
int dpInPixels = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 20, getResources().getDisplayMetrics());
InsetDrawable id = new InsetDrawable(gd, 0, dpInPixels, 0, 0);
rl.setBackground(id);