Android Studio - 椭圆形视图显示为正方形

Posted

技术标签:

【中文标题】Android Studio - 椭圆形视图显示为正方形【英文标题】:Android Studio - Oval shape view is appearing as a square 【发布时间】:2022-01-08 00:10:40 【问题描述】:

我有一个背景设置为椭圆形的视图。

<View
        android:id="@+id/circleView"
        android:layout_
        android:layout_
        android:background="@drawable/bg_circle"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

这是我的 bg_c​​ircle.xml 文件

<shape xmlns:android="http://schemas.android.com/apk/res/android">
    android:shape="oval">
    <solid android:color="@android:color/holo_green_light" />
    <size
        android:
        android: />
</shape>

我尝试在两个文件中将宽度和高度设置为相同的值,但仍然不起作用。我的视图显示为正方形。如何解决这个问题?谢谢。

【问题讨论】:

【参考方案1】:

这是正确的

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="@android:color/holo_green_light" />
<size
    android:
    android: />
</shape>

你错了

<shape xmlns:android="http://schemas.android.com/apk/res/android">

上面一行,你已经加了">"这个,不用加了。

如果不起作用或者你不明白,请告诉我。

【讨论】:

以上是关于Android Studio - 椭圆形视图显示为正方形的主要内容,如果未能解决你的问题,请参考以下文章

圆形图像视图显示方形图像

新活动的圆形展示过渡

Recycler视图在android studio中未显示一张卡片视图

回收站视图未在 android studio 中显示一张卡片视图

如果在 Android Studio 上突出显示至少一个子视图,则突出显示可扩展列表视图的标题视图

为啥视图没有显示在 android studio 的设计中?