The sample Demos API has an example of such a layout. The following page links to samples:
http://developer.android.com/resources/samples/index.html
Locate the LinearLayout9.java file and the corresponding linear_layout9.xml layout file. For convenience, I inserted them here:
LinearLayout9.java:
package com.example.android.apis.view; import com.example.android.apis.R; import android.app.Activity; import android.os.Bundle; import android.widget.ListView; import android.widget.ArrayAdapter; public class LinearLayout9 extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.linear_layout_9); ListView list = (ListView) findViewById(R.id.list); list.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, AutoComplete1.COUNTRIES)); } }
linear_layout9.xml:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <ListView android:id="@+id/list" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1.0" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/linear_layout_9_button" /> </LinearLayout>
Tyler collier
source share