i want to add two buttons like - Dislike in right corner. i can do
that layout perfectly but how to add that two button dynamically that
i don't know.
As per my thinking relative layout is only way to achieve this output.
if there are any alternative solution please share it.
RelativeLayout
is not the single way to do it but it's the most efficient way to do it. You could, for example wrap the ImageView
in a FrameLayout
and also put those two two Buttons
in a horizontal LinearLayout
. You'll then place that LinearLayout
in the FrameLayout
using layout_gravity
set to bottom|right
. But RelativeLayout
is the way to go because you'll avoid using an extra layout between the wrapper container and the two Buttons
. For a RelativeLayout
you'll have at the end of the layout:
<RelativeLayout>
<ImageView width|height=fill_parent />
<Button width|height=wrap_content android="@+id/dislike"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true" />
<Button width|height=wrap_content android="@+id/like"
android:layout_toLeftOf="@id/dislike"
android:layout_alignParentBottom="true" />
</RelativeLayout>
If you add the Buttons
in code you would set RelativeLayout.LayoutParams
for the Buttons
and also set the appropriate rules as in the xml layout for those LayoutParams
.