Android - 如何编辑 RelativeLayout 形状

Android - How to edit RelativeLayout shape

我正在使用带有布局的 window 作为 Activity class 的弹出窗口,当按下 button 时,将出现一个弹出窗口 window。我想要的是编辑弹出 window 的 shape,即 RelativeLayout。谢谢

这是我的pop_up.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/layout_shape"
    tools:context="com.example.computer.mathkiddofinal.FinalResults.Final_Result_Grade_4">

</RelativeLayout>

这是我的 layout_shape

    <solid
        android:color="#00B0BE" >
    </solid>

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

    <padding
        android:left="5dp"
        android:top="5dp"
        android:right="5dp"
        android:bottom="5dp"    >
    </padding>

    <corners
        android:radius="40dp"   >
    </corners>

</shape>

我的 XML 的屏幕截图,我想删除侧面的空白,我从布局背景中知道它,我可以使用透明度吗?因为这会在其他布局上弹出 activity 所以我只需要蓝色形状。顺便说一句,布局代码来自@Sabari 谢谢

试试这个:-

添加自定义绘图

custom_shape.xml

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

    <solid
        android:color="#00B0BE" >
    </solid>

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

    <padding
        android:left="5dp"
        android:top="5dp"
        android:right="5dp"
        android:bottom="5dp"    >
    </padding>

    <corners
        android:radius="40dp"   >
    </corners>

</shape>

并为 RelativeLayout 添加背景

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/transparent">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/custom_shape">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Testing" />
    </RelativeLayout>
</RelativeLayout>

只要改变你的,

layout_shape如下,

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/listview_background_shape">
    <stroke
        android:width="2dp"
        android:color="#ff207d94" />
    <padding
        android:bottom="2dp"
        android:left="2dp"
        android:right="2dp"
        android:top="2dp" />
    <corners android:radius="5dp" />
    <solid android:color="#2eb8b8"></solid>
    <corners android:radius="30dp"></corners>
</shape>

pop_up.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#00000000">

    <RelativeLayout xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/layout_shape"
        tools:context="com.example.computer.mathkiddofinal.FinalResults.Final_Result_Grade_4">

    </RelativeLayout>
</RelativeLayout>

您只需减小自定义形状中角的半径

<corners android:radius:"10dp"></corners>