繁体   English   中英

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

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

我正在做一个 android 项目,我正在尝试在一个圆圈内创建一个像星星一样的图像

像这个在此处输入图像描述

我已经尝试过,但我无法调整星星的大小。

每次我尝试调整明星 android 工作室调整我的整个图像大小

在此处输入图像描述

这是我的圆形 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>

这是我的明星 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>

这是我的布局

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

请告诉我我该怎么做

我有类似的问题,我使用以下方法修复了它。

您可以在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 -->
        

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