I want to draw a square shape every time I can use it. The barcode shown is only representative. I want to make a drawing that I can give the dimensions of the square like the picture. how can I do that ? what can i research? I would like to do this by assigning measures in the MainActivity class that I write to a specific class.
Asked
Active
Viewed 1,073 times
1 Answers
2
Make a drawable with the following xml:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#000000" />
</shape>
This will generate a solid black rectangle, if you want a rectangle with borders around it use this code instead:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="#000000" />
<stroke android:color="#c4441d" android:width="5dp" />
</shape>
once you have made the drawable, say rect.xml. You can use it in your layout as follows:
<ImageView
android:layout_width="100dp"
android:layout_height="50dp"
android:src="@drawable/rect" />
More details here: http://devdeeds.com/how-to-create-rectangle-shape-using-xml-in-android/
If you want to do it within code, please take a look at this existing question: Android canvas draw rectangle

Vardaan Sharma
- 1,125
- 1
- 10
- 21
-
Is it the same as what I wrote and what you wrote? do you send me a picture – user9304297 Feb 08 '18 at 14:50