tags:

views:

46

answers:

2

Hi all!

The best way to ask this question is to provide an example, so here it is:

<ScrollView>
    <LinearLayout
        android:id="@+id/main"
        android:orientation="vertical"
    >
        <TextView
            android:id="@+id/some_text"
        />
        <LinearLayout
            android:id="@+id/stretch_me"
        />
        <Button
            android:id="@+id/i_can_toggle"
        />
        <TextView
            android:id="@+id/toggle_me"
            android:visibility="gone"
        />
        <Button
            android:id="@+id/finished"
        />
    </LinearLayout>
</ScrollView>

This seems fairly simple, but hold on ...

1) I would like the stretch_me layout to take all the remaining space on the screen (and I need its size so I can dynamically populate it from code)

2) I can't change main to RelativeLayout because I would like to toggle toggle_me between gone and visible using the i_can_toggle but need to keep strech_me size the same as before

3) Before changing toggle_me to visible there must be no scroll and finished button must be positioned at the bottom of the screen

Now I have tried many things and the most promising approach was this one with some coding (I was thinking about setting the stretch_me size from code), but I was not able to get the size of the view from my onCreate() method (screen_height - view_height = remaining space).

Any ideas?

Thanks!

A: 

Hi,

Set stretch_me to have these attributes to make it take up the space

android:layout_height="fill_parent"
android:layout_weight="1"
ognian
What would that change?
LambergaR
It'll have the view measured twice and fill the space left by other views
ognian
A: 

I would like the stretch_me layout to take all the remaining space on the screen

Set the height and weight parameters to the following

android:layout_height="fill_parent"
android:layout_weight="1"

I need its size

You can use onmeasure() to measure the view size. http://developer.android.com/reference/android/view/View.html#onMeasure(int, int)

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    int widthSpec = MeasureSpec.getMode(widthMeasureSpec);
    int width = MeasureSpec.getSize(widthMeasureSpec);
    //Similarly for height
}
primalpop
I don't think I can use this since I have it in a ScrollView
LambergaR