如何在Android中可绘制的正方形内绘制点圆? [英] How to draw a dot circle inside a square drawable in android?
问题描述
我想要一个方形按钮内的小点,这是我直到azizbekian回答的尝试:
I want a small dot inside a square button , this is what i have tried till now as answered by 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>
第一张图片是我尝试过的,第二张图片是我想要排除文本的.
The first image is what i have tried and the second image is what i want excluding the text.
而且此代码也是我必须将drawable应用到的按钮 水平线形布局中有七个这样的按钮,权重总和为100:每个按钮的权重为14
and also this code is the button to which i have to apply the drawable there are seven such buttons in an horizontal linearlayout with weightsum:100 each button has weight 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"/>
当将此可绘制对象应用于按钮时,圆点不会出现在背景中,可能是因为按钮和可绘制对象的大小,我试图调整可绘制对象的大小,但是我只是不理解而已,并且它不起作用,如何调整它,使点出现在按钮背景中.
the dot does not appear in the background when this drawable is applied to the button, maybe because of the size of button and drawable i tried to adjust the size of drawable, but i just do not understand it and it did not work, how can i adjust it such that the dot appears in button background.
推荐答案
这是
ImageView的src为dotted.xml.
ImageView has src to 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>
这篇关于如何在Android中可绘制的正方形内绘制点圆?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!