How do I get a view's height to fill the space in between tw

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

How do I get a view's height to fill the space in between tw

Postby TinyGrasshopper » Sun Oct 25, 2009 5:54 am

Hello,

I have very little experience with Android and Java, but in any case, I'm trying to make a layout that kinda looks like the gmail inbox layout. I have a textview on top with a scrollview with a radio group of radio buttons in it below that and a linearlayout of buttons beneath that, but i want the linearlayout of buttons to stick to the bottom of the screen and the scrollview to be sized so that its bottom meets the top of the row of buttons.

The closest thing that I can come up with is a relativelayout holding the three items. with the textview on top and the scrollview beneath that set with the android:layout_below attribute and the linearlayout at the bottom set with the android:layout_alignParentBottom attribute set to true. The problem is that the scrollview's height when set to either fill_parent or wrap_content stretches out to the bottom of the screen sitting behind the row of buttons.

I figure this has to be done programatically, but I'm not sure how to do that. Is there a resize or setHeight method and where would I call it?

I assume that I have to use setHeight (if there is such a thing) and getHeight on the other views to get their height and resize the scrollview accordingly. I'm also assuming that there is a onSizeChanged for the views that would get resized and I would call it from there? That would mean that I'd have to make a new class extending the textView that would resize the scrollview from there? and if i'm make a new class how do i initially put that in the xml? (Admittedly I'm not sure about the details of most of that so it sounds like a lot to me)
TinyGrasshopper
Junior Developer
Junior Developer
 
Posts: 10
Joined: Sun Oct 25, 2009 5:25 am

Top

Postby azraeal » Sun Oct 25, 2009 7:25 am

Redesign your layout as follows:

Replace your RelativeLayout with a LinearLayout. Set its orientation to be vertical. Then, for each of its children, assign them a weight. So, you'd have a weight of 1 for the textview and other linearlayout and maybe a 5 for your scollview. Adjust the weights as you see fit. They should all fit nicely on 1 screen.
azraeal
Experienced Developer
Experienced Developer
 
Posts: 71
Joined: Fri Sep 04, 2009 6:34 pm
Location: California

Thanks

Postby TinyGrasshopper » Tue Oct 27, 2009 3:29 am

Thanks so much.

I tried the LinearLayout before trying the RelativeLayout and I couldn't get it work but it worked this time. I set the layout_weight of the scrollview to 1 and the layout_weight of the textview and the linearlayout to 0 each and the scrollview filled out the screen.

the layout_weight helped me with the row of buttons at the bottom too. I gave them a higher weight and they filled out the width of the screen as well.
TinyGrasshopper
Junior Developer
Junior Developer
 
Posts: 10
Joined: Sun Oct 25, 2009 5:25 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 6 guests