How To Manage Control In Relative Layout Dynamically?
Solution 1:
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><ImageViewwidth|height=fill_parent /><Buttonwidth|height=wrap_contentandroid="@+id/dislike"android:layout_alignParentRight="true"android:layout_alignParentBottom="true" /><Buttonwidth|height=wrap_contentandroid="@+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
.
Solution 2:
Question is not very clear ...yet if you want to add buttons dynamically or show the buttons based on some condition ..you can always add it in your layout and set the Visibility as INVISIBLE and later in your code can show your buttons by settings Visibility as VISIBLE.
Post a Comment for "How To Manage Control In Relative Layout Dynamically?"