MrGibbage
MrGibbage

Reputation: 2646

Android layout textview and listview combined

I am trying to layout a home automation app. The top part of the screen will be custom status text (Garage door is OPEN, System is DISARMED, etc). Under the status text there will be a refresh link/button/list item. Something that the user can click on to refresh the status text. At the bottom will be a listview that will be links to other pages and links to actions such as "Security Page", or "Close Garage Door", etc. My question is, how do I configure the layout? I have tried several LinearLayouts, RelativeLayouts, nested layouts, etc, and none have worked so far. Here is my main.xml as of now:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout        
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content" >
        <TextView 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:id="@+id/statustext">
        </TextView>
    </LinearLayout>
    <LinearLayout 
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content" >
        <TextView 
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content"
            android:id="@+id/refresh">
        </TextView>
    </LinearLayout>
    <LinearLayout 
        android:orientation="vertical" 
        android:gravity="center_horizontal" 
        android:layout_height="fill_parent" 
        android:layout_width="fill_parent">
        <ListView 
            android:layout_width="fill_parent" 
            android:id="@android:id/list" 
            android:layout_height="wrap_content">
        </ListView>
    </LinearLayout>
</LinearLayout>

The refresh link could just be an item of the listview, but I would like to style it differently so it stands out, such as a different color font or background. Or it could be a button. But it needs to be between the statustext and itemlist. And everything should scroll as one unit.

Is this possible? My Layout

Upvotes: 2

Views: 7403

Answers (2)

Hitendra
Hitendra

Reputation: 3226

Add you status text content to listheaderview.here is the link for that. Android listview with header and footer buttons This way the whole list ll be scrolled with your status text.

Upvotes: 1

datalost
datalost

Reputation: 3773

Is this works?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<ScrollView android:id="@+id/ScrollView01"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent">

   <LinearLayout android:gravity="center|center_vertical"
    android:orientation="vertical" android:layout_height="fill_parent" android:layout_width="fill_parent">
    <TextView 
            android:gravity="center_horizontal"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:text="status" 
        android:id="@+id/statustext">
    </TextView>
    <TextView 
            android:gravity="center_horizontal"
        android:layout_height="wrap_content"
        android:text="refresh"
        android:id="@+id/refresh" android:layout_width="fill_parent" android:layout_gravity="fill_horizontal">
    </TextView>
    <ListView 
            android:gravity="center_horizontal"
        android:layout_width="fill_parent" 
        android:id="@android:id/list" 
        android:layout_height="wrap_content">
    </ListView>
    </LinearLayout>
    </ScrollView>
</LinearLayout>

If you want to have a scroll bar, use ScrollView to warp all sub-items. But ScrollView it self can host only one direct child so you'll need to wrap them all with a LinearLayout which has everything you want inside.

Upvotes: 1

Related Questions