Chintan Khetiya
Chintan Khetiya

Reputation: 16142

How to manage control in relative layout Dynamically?

One designing issue in relative layout. Actually i want this type out output.

enter image description here

This all should be dynamically. I inspire from Android heterogeneous gridview like pinterest?

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.

Please guide me it's truly appreciated.

Thanks for analyze my question.

Upvotes: 2

Views: 825

Answers (2)

user
user

Reputation: 87064

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.

Upvotes: 1

Nargis
Nargis

Reputation: 4787

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.

Upvotes: 0

Related Questions