I’m new to Android development. I am trying to create a layout based on this image. How do I manage to align the image with a border and padding to the edge and positioned to the right? Thank you very much
Second: Paddings could be modified in the layout XML file directly to elements. There are many options to set padding, if I’ve understood your exact aim one of these 2 properties might be useful:
android:padding="planned_pad-dp"
or to specify different padding in height & width:
2
Answers
It is based on the parent view you use. Using
ConstraintLayout
makes it easier to align images w.r.t sibling or parent views.When the parent view is
ConstraintLayout
, then you can use the properties:app:layout_constraintBottom_toBottomOf="viewId"
app:layout_constraintEnd_toEndOf="viewId"
app:layout_constraintStart_toStartOf="viewId"
app:layout_constraintTop_toTopOf="viewId"
you can align your view with the another view with it’s
id
or you align relative to yourparent
view.This code might help you.
First: To align a view to right side of a constraint parent layout, add this attribute to your customized view:
& It’s better to assign an ID to the container layout and to use that ID to relate the view to the parent layout. for example, my layout ID is:
& aligning attribute code:
Second: Paddings could be modified in the layout XML file directly to elements. There are many options to set padding, if I’ve understood your exact aim one of these 2 properties might be useful:
or to specify different padding in height & width:
Third: To set a customized shape to the image view including the border.
a- From this path create a drawable XML file:
res->drawable->right_click->new->drawable resource file
*In the displayed window change the root property to: "shape & set other settings.
b- Use these attributes to customize your XML file:
c- Declare a relative layout in the image holder activity’s or fragment’s res.xml file. set its background attr. the designed XML file:
d- Insert your image view in the relative layout & set alignments.