I wonder if I can draw rectangle in XML.
I know how to draw using drawRect method programmatically.
I wonder if I can draw rectangle in XML. I know how to draw
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes you can and here is one I made earlier:
You can create a new XML file inside the drawable folder, and add the above code, then save it as rectangle.xml.
To use it inside a layout you would set the
android:backgroundattribute to the new drawable shape. The shape we have defined does not have any dimensions, and therefore will take the dimensions of the View that is defined in the layout.So putting it all together:
Finally; you can set this rectangle to be the background of any View, although for ImageViews you would use
android:src. This means you could use the rectangle as the background for ListViews, TextViews…etc.