Dazzmaster1
Dazzmaster1

Reputation: 169

Two Layouts on Android Screen

I am trying to make an application that will have a set of screens that are similar in the fact that they will have a layout at the top, and at the bottom will have a set of buttons. Basically what happens is that one of the buttons at the bottom is a spinner, and each of the options that gets selected should inflate a layout into the top half of the screen, while leaving all of the buttons at the bottom.

What is the best way of going about this, without having to rewrite the part of the xml for the buttons at the bottom of the screen.

Screen Shot From the image above, I need the five buttons at the bottom to stay the same for all screens, while everything above it needs to be changed when one of the options is selected from the spinner.

My code currently is as follows: It currently puts up the buttons at the bottom, and the text in the red box, which will be on every screen. What I need to do is inflate the personal layout into the space in between. setContentView(R.layout.people1);

if (v.getId() == R.id.service_user_button)
{
    Spinner spinner = (Spinner) findViewById(R.id.people_spinner);
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
                getBaseContext(), R.array.service_user_array, android.R.layout.simple_spinner_item);

adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            spinner.setAdapter(adapter);


}

Upvotes: 2

Views: 2088

Answers (3)

Gangnus
Gangnus

Reputation: 24464

There exists one more additional (not alternative!) possibility. The whole activity screen is always inserted into a FrameLayout. So, you can use as a root layout Merge instead of a root layout. The layout with buttons will have large top margin, so they will be placed at the bottom. Other layouts will be at the top, as they are. The theory is described here.

Of course, the common bottom layout should be placed into include.

Upvotes: 0

Macarse
Macarse

Reputation: 93123

You can also use the <include> tag. Check this explanation by Romain Guy.

Upvotes: 0

Reuben Scratton
Reuben Scratton

Reputation: 38707

You want your layout to look something like this:

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    >
    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        >
        <LinearLayout
            android:id="@+id/theContent"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            />
    </ScrollView>

    <!-- Buttons go inside this -->        
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"

         />

</LinearLayout>

At runtime you lookup the LinearLayout with the id 'theContent' and assign it's children to it.

Upvotes: 3

Related Questions