2

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.

Community
  • 1
  • 1
Chintan Khetiya
  • 15,962
  • 9
  • 47
  • 85
  • *add two buttons like - Dislike in right corner* - to all of those squares(`ImageViews`) or for the whole screen? – user Dec 10 '12 at 08:00
  • for each. as i show in my sketch image.All images retrieve form web. so user can like-dislike any of the image. i use the reference link and its really good but that two buttons is my additional requirement. so i am confuses how to do it ? – Chintan Khetiya Dec 10 '12 at 08:02

2 Answers2

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>
   <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.

user
  • 86,916
  • 18
  • 197
  • 190
  • thanks for wonderful answer. but if i use relative layout then i how can i get images in 3 vertically column. this is by xml formatting.but if i use dynamically then not get. – Chintan Khetiya Dec 10 '12 at 08:32
  • @chintankhetiya The images are supposed to only fill the screen or do you plan to have much more needing to scroll them? – user Dec 10 '12 at 08:36
  • scroll can be add in xml. and i can't understand how to do this with relative layout. can i update my code ? – Chintan Khetiya Dec 10 '12 at 08:39
  • @chintankhetiya If you plan to have more images than the screen can fit then you shouldn't use a simple `RelativeLayout`, you would need some kind of `AdapterView` so you can use some sort of recycling mechanism. The layout can be made with a `RelativeLayout`(with very poor performance) but to actually built it you would need to have precise information about those images. – user Dec 10 '12 at 08:45
  • yes. there should be not fix images either 20 or 50 as per request. i think i have to use custom grid view. i am thinking if i use relative layout then in landscape mode it will change its position.am i right ? – Chintan Khetiya Dec 10 '12 at 08:49
  • @chintankhetiya When changing the orientation of the screen the `RelativeLayout` will keep all of its children positioning. – user Dec 10 '12 at 08:50
  • is it ? because when i create one screen in that they changing its position.so what i have to do ? make custom adapter view ? – Chintan Khetiya Dec 10 '12 at 08:53
  • @chintankhetiya The position will not remain exactly the same because the screen real estate changes but the rules remain. Yes you'll need a custom AdapterView to position the children like you want. That isn't quite an easy task to do. – user Dec 10 '12 at 08:58
  • Luksprog Thanks. yes i know that.i just start with same task. – Chintan Khetiya Dec 10 '12 at 09:00
  • Luksprog can you help me ? – Chintan Khetiya Dec 11 '12 at 06:22
  • @chintankhetiya Sorry making that kind of view it's a complex task, but look at the other question from the link in your question and see if you may do something with the code from there. – user Dec 11 '12 at 07:09
  • i just want to change some things. if you are free to analyze me code please it will be good for me. i want to add sub layout and add that two button in that see this http://pastebin.com/Q000x9TS copy past and i wan this type of output dynamically. – Chintan Khetiya Dec 11 '12 at 07:43
0

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.

Nargis
  • 4,687
  • 1
  • 28
  • 45
  • have you read my reference link? i got same output in linear layout. but that is only for single image, i want that each gallery image have like -dislike button so user can set his/her rank. in that image should be clickable that i have done. but how to add that two button on right corner of each image. – Chintan Khetiya Dec 10 '12 at 07:37
  • if you are using a GridView then use a custom adapter and inflate layouts including image and buttons. then you can do what is suggested by @chintankhetiya – Ali Imran Dec 10 '12 at 07:42
  • @AliImran but in grid view i will not get same output as i want. i already tried that. if you have any reference link with same output please share it. – Chintan Khetiya Dec 10 '12 at 07:45