Modify your circle_layoutinner RelativeLayout declaration to indicate the height in dp instead of wrap_content and get rid of 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" >
define circle_inset_drawable.xml to offset the orange circle by the correct amount:
<inset xmlns:android="http://schemas.android.com/apk/res/android" android:drawable="@drawable/circletwo" android:insetTop="20dp" android:visible="true" />
insetTop should be circle_layout height minus circle_layoutinner height
You can set the color of the drawn code this way. You just need to start with your layout object, and then continue to wade through the objects until you get to the one that allows you to set the color:
RelativeLayout rl = (RelativeLayout)findViewById(R.id.circle_layoutinner); InsetDrawable id = (InsetDrawable)rl.getBackground(); GradientDrawable gd = (GradientDrawable)id.getDrawable();
Or you can create an InsetDrawable in the code as follows:
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);
source share