you786
you786

Reputation: 3550

Android Buttons in ScrollView sized to half the screen

I want to be able to scroll through buttons in a scrollview, and have each button be half the size of the screen.

_____________
/__________\
| BUTTON 1 |
\__________/

/__________\
| BUTTON 2 |
\__________/
_____________

...scroll a bit...

_____________
| BUTTON 1 |
\__________/

/__________\
| BUTTON 2 |
\__________/
_____________

... bit more...

_____________
\__________/

/__________\
| BUTTON 2 |
\__________/

/__________\
| BUTTON 3 |
_____________

If it was just in a LinearLayout, I'd use layout_weight set to 1, but I don't think that would work in a ScrollView.

Upvotes: 2

Views: 395

Answers (2)

10s
10s

Reputation: 1699

You are almost correct. ScrollView must have one direct child beneath it. So add the scrollview as the parent layout and a linear layout inside it and do whatever you want.

UPDATE: Now I get what you mean. Then you should get the screen width and height, do some mathematics and adjust the height and width attribute of your buttons to the desired ones.

Maybe extend the button class in order to just implement it one time and then include it in your layout xml as a custom view. The way I see it there isn't some layout parameters you could pass in order to adjust the buttons' size.

Upvotes: 0

you786
you786

Reputation: 3550

As I thought, you'd almost definitely have to do this programatically with screen measurements. I just switched to using a ViewFlipper and previous/next buttons.

Upvotes: 1

Related Questions