Android 如何给出布局圆角

Android 如何给出布局圆角,android,xml,android-layout,android-shape,Android,Xml,Android Layout,Android Shape,我试图在屏幕中央显示一个半透明背景的活动。可绘制的有圆角,我已经设置了一个矩形形状,圆角作为布局的背景。该形状具有可绘制的背景。问题是,我仍然得到一个黑色的方形边框后面的圆角拉丝。有没有办法摆脱那黑色的边界 我想我不能发照片是因为我没有名声 以下是布局的xml: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/custom_toast_layout

我试图在屏幕中央显示一个半透明背景的活动。可绘制的有圆角,我已经设置了一个矩形形状,圆角作为布局的背景。该形状具有可绘制的背景。问题是,我仍然得到一个黑色的方形边框后面的圆角拉丝。有没有办法摆脱那黑色的边界

我想我不能发照片是因为我没有名声

以下是布局的xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/custom_toast_layout_id"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"    
    android:orientation="horizontal"
    android:padding="5dp"   
    android:gravity="center"
    android:background="@drawable/myshape" >


    <TextView
        android:id="@+id/text1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="hello"
        android:textColor="#000000"
        android:textSize="30sp" />


</RelativeLayout>

以下是形状的xml:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:drawable="@drawable/blank_colordots_test">
        <shape android:shape="rectangle" android:padding="10dp">             
            <corners
                android:bottomRightRadius="35dp"
                android:bottomLeftRadius="35dp"
                android:topLeftRadius="35dp"
                android:topRightRadius="35dp"/>
        </shape>
    </item>
</layer-list>

尝试以下代码:

rounded_drawable.xml

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

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

    <solid android:color="#565656" />

    <stroke
        android:width="3dp"
        android:color="#ffffff" />

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

</shape>

声明此样式:

  <style name="ThemeWithCorners" parent="android:Theme.Dialog">

          <item name="android:windowNoTitle">true</item>
    </style>

真的

在清单中应用此样式。

这应符合您的要求:

//布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="10dp"
    android:background="@drawable/myshape"
    android:gravity="center">


    <TextView
        android:id="@+id/text1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="hello"
        android:textColor="#000000"
        android:textSize="30sp" />

</RelativeLayout>

//形状:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:bottom="0dp"
        android:left="0dp"
        android:right="0dp"
        android:top="0dp">
        <shape android:shape="rectangle">
            <solid android:color="#000000" />
            <corners android:radius="4dp" />
            <stroke
                android:width="1dp"
                android:color="#000000" />
        </shape>
    </item>
</layer-list>


您可以尝试使用上述代码为布局指定边框。您可以根据需要更改拐角半径和颜色。我用红色作为边框

这个解决方案看起来真的很不错,但我提到的黑色方形边框仍然存在。我仍然想摆脱它。这个解决方案仍然有我提到的黑色方形边框,实际上它更大。虽然这个代码片段可能是解决方案,但确实有助于提高您的帖子质量。记住,你是在回答未来读者的问题,这些人可能不知道你的代码建议的原因。不鼓励只使用代码的答案,因为它们不会为未来的读者提供太多信息。请对你所写的内容进行解释。谢谢@whats你的建议……这是我的第一个答案。谢谢@yivi你的建议……这是我的第一个答案。
GradientDrawable border = new GradientDrawable();
    border.setColor(Color.rgb(255,255,255));
    border.setStroke(8, Color.red);
    border.setCornerRadius(20);
    yourview.setBackground(border);