Android how to create view like this in Circular shape having imageview and text view

后端 未结 2 950
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-14 08:49

i want to create a view like this i have posted in screen shot, in circle shape of layout with one image view with some background colour and one text view just below the i

相关标签:
2条回答
  • 2021-01-14 09:29

    Change your declaration of the circle_layoutinner RelativeLayout to specify a height in dp instead of wrap_content and get rid of the 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 the height of circle_layout minus the height of circle_layoutinner

    You can set the color of the drawable in code like this. You just need to start with your layout object and then keep on burrowing down through the objects until you get to the one that lets you set the color:

    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
    

    Or you can create the InsetDrawable in code like this:

    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);
    
    0 讨论(0)
  • 2021-01-14 09:38

    Try to create the image with orange n white colour u expected.

    set it as background to LL or RL

    Simply use an ImageView and Textview with appropriate dimension to display the info.

    0 讨论(0)
提交回复
热议问题