如何在相对布局中使用边框(可绘制)?

Bry*_*anT 2 android android-layout

我有这样的可绘制(xml)。

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners android:radius="10dp"/>
<padding android:left="5dp" android:right="5dp" android:top="5dp" android:bottom="5dp"/>
<solid android:color="#FF00FF00"/>
</shape>
Run Code Online (Sandbox Code Playgroud)

我的按钮在父线性布局内。

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:background="@drawable/custombordergreen"
    android:orientation="vertical">

    <Button
        android:id="@+id/startClock"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="204dp"
        android:layout_height="66dp"
         android:text="@string/start"
        android:textSize="22sp"
        android:layout_gravity="center_horizontal"
        android:background="@drawable/startbutton"/>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

但是,如果按钮已经是相对布局中的同级(并在“ toLeftOf”中引用),则无法使用该技术。

缺少重新布局以避免“相对”布局的方法,还有另一种方法可以在按钮周围放置边框吗?

Gop*_*ngh 5

将此作为您的按钮背景

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

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

<stroke
    android:width="0.5dp"
    android:color="#111111" />

<corners
    android:bottomLeftRadius="05dp"
    android:bottomRightRadius="05dp"
    android:topLeftRadius="05dp"
    android:topRightRadius="05dp" />
</shape>
Run Code Online (Sandbox Code Playgroud)