简体   繁体   English

如何在 android 工作室中调整圆圈内的图像大小?

[英]How to resize image inside circle in android studio?

I am working on an android project where i am trying to create an image like a star inside a circle我正在做一个 android 项目,我正在尝试在一个圆圈内创建一个像星星一样的图像

like this one像这个在此处输入图像描述

I have tried but i am unable to resize the star.我已经尝试过,但我无法调整星星的大小。

Every time i try to resize star android studio resize my whole image每次我尝试调整明星 android 工作室调整我的整个图像大小

在此处输入图像描述

this is my circle shape xml :这是我的圆形 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 :这是我的明星 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请告诉我我该怎么做

I had the similar problem and I fixed it using below methods.我有类似的问题,我使用以下方法修复了它。

You can either add padding inside your ImageView您可以在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中设置scaleType属性以适应您的需要。

    <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 -->
        

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM