0

I want to create a layout where a listview always show the data above the bottom button. How to do that. Here are the different options given below
I option

item1
item2
button
empty space
empty space
empty space
empty space
empty space
empty space

II option

item1
item2
item3
item4
item5
item6
item7
item8
button

III option

item3
item4
item5
item6
item7
item8
item9
item10
button

How to realise this layout with list and button? For example, if I have 15 items than access to items by scroll (ScrollView solve this problem) and button is visible.

androidcodehunter
  • 21,567
  • 19
  • 47
  • 70
  • what you want to do??? and what you are trying to say, can you please explain in brief... – InnocentKiller Dec 03 '13 at 18:03
  • IV option: I have dynamicaly changing count of TextView and Button. When TextView count more than screen size (if I use LinearLayout and some count of TextView, Button as childs) than Button doesn't visible. How to solve this?! – user3062595 Dec 03 '13 at 18:12

2 Answers2

0

I understand your question. Create a layout with a ListView and create another layout with a button. Now add the Button layout as a footer of this ListView layout.
ListView Layout will be like this

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <ListView
        android:id="@+id/myListView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
</RelativeLayout>

Now the Button Layout is

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <Button
        android:id="@+id/myButton"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
</RelativeLayout>

You can dynamically add footer in a ListView. It is perfect solution for you. Checkout the answer How to add footer in Listview

For your purpose I can re-write the code as a sample. Please check it and play with it.

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <LinearLayout
            android:id="@+id/layoutOption1"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical"
            android:visibility="visible" >

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="Item 1" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="Item 2" />

            <Button
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="My Button" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/layoutOption2"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical"
            android:visibility="gone" >

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="Item 1" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="Item 2" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="Item 3" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="Item 4" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="Item 5" />

            <Button
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="My Button" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/layoutOption3"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical"
            android:visibility="gone" >

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="Item 1" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="Item 2" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="Item 3" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="Item 4" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="Item 5" />

            <Button
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="My Button" />
        </LinearLayout>
    </RelativeLayout>

</ScrollView>

In your activity class get the id of each layout option and setVisibility for your purpose. In your requirement I wrote this code for your. Thanks.

Community
  • 1
  • 1
androidcodehunter
  • 21,567
  • 19
  • 47
  • 70
0

If you want use ScrollView try this:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <ScrollView
        android:id="@+id/scroll"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:layout_alignParentTop="true"
        android:layout_above="@+id/LastButton">

        <LinearLayout
            android:id="@+id/layout1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="Item 1" />
            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="Item 2" />
            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="Item 3" />
            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="Item 4" />
            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="Item 5" />
            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="Item 6" />
            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="Item 7" />

        </LinearLayout>

    </ScrollView>

    <Button
        android:id="@+id/LastButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:text="Last Button" />

</RelativeLayout>  

LastButton nead android:layout_alignParentBottom="true" in order to stay visible when LinearLayout grows.

ramaral
  • 6,149
  • 4
  • 34
  • 57