背景有两种颜色的布局,背景中两种颜色之间放置一个圆形图像,圆形图像上有一个边框

Layout with two colors for the background, a rounded image placed between the two colors in the background and a border on the round image

我对 Android Studio 还是很陌生,布局仍然令人困惑。SwiftUI 只有 3 个堆栈可以使用,使这种方式更容易。无论如何,我会附上一张图片,展示我正在努力实现的目标。我想要两种颜色的背景,在背景中的两种颜色之间放置一个圆形图像,并在圆形图像上添加一个边框。

Ex of what I am looking for

要执行您想要的操作,首先您必须在可绘制资源文件夹中创建一个新的 xml 文件。为此,请单击 res > drawable。右键单击 drawable 并创建一个新的 xml 文件。给它起个名字,然后在其中添加以下代码。

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

    <stroke android:color="#000000" android:width="2dp"/>

    <solid
        android:color="@color/colorPrimary"/>
</shape>

描边是轮廓,实心是椭圆的填充色。您可以修改颜色值。 然后在你想要一个如图所示按钮的布局中,添加

<ImageButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:background="@drawable/circle_bg"
        android:src="@drawable/ic_baseline_image_24"/>

可以将填充修改为您希望背景轮廓与图像的接近程度。 src 是您的图像。如果您希望按钮图像更大,请按住 command 或 control(取决于您是否使用 mac),然后单击您放入源代码的路径。

点击后您应该会看到以下内容:

如果图片看起来太小,请根据自己的喜好修改宽度和高度。