0

I am working on an android project where i am trying to create an image like a star inside a circle

like this one enter image description here

I have tried but i am unable to resize the star.

Every time i try to resize star android studio resize my whole image

enter image description here

this is my circle shape xml:

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">

    <solid
        android:color="@color/darkPurple"/>

    <size
        android:width="50dp"
        android:height="50dp"/>
</shape>

this is my star xml:

<vector android:autoMirrored="true" android:height="1dp"
    android:tint="#FFB404" android:viewportHeight="24"
    android:viewportWidth="24" android:width="1dp" xmlns:android="http://schemas.android.com/apk/res/android">
    <path android:fillColor="@android:color/white" android:pathData="M12,17.27L18.18,21l-1.64,-7.03L22,9.24l-7.19,-0.61L12,2 9.19,8.63 2,9.24l5.46,4.73L5.82,21z"/>
</vector>

This is my layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:orientation="vertical"
        android:layout_weight="1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        >
        <ImageView
            android:layout_gravity="center"
            android:background="@drawable/circle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_baseline_star_24"
            >

        </ImageView>
        <TextView
            android:layout_gravity="center"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Markets"
            android:textColor="@color/white"
            >

        </TextView>

    </LinearLayout>

    <LinearLayout
        android:orientation="vertical"
        android:layout_weight="1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <ImageView
            android:layout_gravity="center"
            android:background="@drawable/circle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_baseline_star_24"
            >

        </ImageView>
        <TextView
            android:layout_gravity="center"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Markets"
            android:textColor="@color/white"
            >
        </TextView>




    </LinearLayout>
    <LinearLayout
        android:orientation="vertical"
        android:layout_weight="1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <ImageView
            android:layout_gravity="center"
            android:background="@drawable/circle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_baseline_star_24"
            >

        </ImageView>
        <TextView
            android:layout_gravity="center"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Markets"
            android:textColor="@color/white"
            >
        </TextView>


    </LinearLayout>


    

</LinearLayout>

Please tell me how can i do this

James
  • 1,124
  • 3
  • 17
  • 37
  • 1
    Will this Help you? [link] https://stackoverflow.com/a/14051472/15590269 – Sam Joshua Jun 11 '21 at 06:42
  • 1
    You can look at my answer [here -How to make a circular drawable with stroke, programmatically?](https://stackoverflow.com/a/45608694/8244632) if wants to do it programmatically. Easy and Concise solution. – Lalit Fauzdar Jun 11 '21 at 07:10

1 Answers1

2

I had the similar problem and I fixed it using below methods.

You can either add padding inside your ImageView

    <ImageView
        android:layout_gravity="center"
        android:background="@drawable/circle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_baseline_star_24"
        android:padding="16dp"> <!-- Here is the change -->
        

or set scaleType attribute in ImageView to fit according to your need.

    <ImageView
        android:layout_gravity="center"
        android:background="@drawable/circle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_baseline_star_24"
        android:scaleType="centerInside"> <!-- Here is the change -->
        
Vikas Choudhary
  • 544
  • 5
  • 10