0

我想要一个方形按钮内的一个小点,这是我到目前为止所尝试的,由 azizbekian 回答:

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

    <item>
        <shape android:shape="rectangle">
            <size android:width="100dp" android:height="100dp"/>
            <solid android:color="#38b0ef"/>
        </shape>
    </item>

    <item
        android:bottom="45dp"
        android:left="45dp"
        android:right="45dp"
        android:top="45dp">
        <shape android:shape="oval">
            <stroke android:width="1dp"  android:color="#0c5069"/>
            <size android:width="20dp" android:height="20dp"/>
            <solid android:color="#0c5069"/>
        </shape>
    </item>


</layer-list>

第一张图片是我尝试过的,第二张图片是我想要的,不包括文字。

这就是现在的样子 这就是我想要排除文本的方式

而且这段代码是我必须应用可绘制的按钮,在水平线性布局中有七个这样的按钮,weightsum:100 每个按钮的权重为 14

<Button
   android:id="@+id/wed"
   android:layout_width="0dp"
   android:layout_height="35dp"
   android:layout_marginEnd="1dp"
   android:background="@drawable/my_button_dot"
   android:text="WED"
   android:textAllCaps="true"
   android:textStyle="bold"
   android:textColor="#ffffff"
   android:layout_weight="15"/>

当此drawable应用于按钮时,点不会出现在背景中,可能是因为按钮和drawable的大小我试图调整drawable的大小,但我就是不明白,它不起作用,怎么能我调整它,使点出现在按钮背景中。

4

2 回答 2

1

首先在drawable中创建color_circle

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


  <solid android:color="#ffffff">


  </solid>

 <size
    android:width="48dp"
    android:height="48dp" />


</shape>

接着

    <RelativeLayout
    android:layout_width="64dp"
    android:layout_height="148dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <Button
            android:textAllCaps="true"
            android:textStyle="bold"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="WED" />

    </LinearLayout>


    <View
        android:layout_width="16dp"
        android:layout_height="16dp"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="16dp"
        android:background="@drawable/color_circle" />


</RelativeLayout>

我希望这是你想要的

于 2020-03-08T07:59:51.177 回答
0

这是

ImageView 有 src 到 dotted.xml。

<ImageView
  android:layout_width="178.8dp"
  android:layout_height="178.8dp"
  android:src="@drawable/dotted"
  android:layout_centerInParent="true"
  android:layerType="software" />
add below to drawable/dotted.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
  <stroke
    android:color="@android:color/white"
    android:dashWidth="1px"
    android:dashGap="10px"
    android:width="6.6dp"/>
</shape>
于 2020-06-17T02:50:44.737 回答