Displaying The Button At The End Of The Listview With Linear Layout
I am a newbie in android application development. I faced a problem regarding the displaying a button at the end of the List View. I am using Linear Layout. The application can sho
Solution 1:
Try this and see if it works:
<?xml version="1.0" encoding="utf-8"?><RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"
><ImageViewandroid:id="@+id/contact_image"android:layout_width="wrap_content"android:layout_height="wrap_content" /><Buttonandroid:id="@+id/btn_New"android:width="170dp"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_centerInParent="true"android:layout_alignParentBottom="true"android:layout_marginBottom="20dp"android:text="Click"
/><TextViewandroid:id="@+id/textView"android:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_above="@id/btn_New"android:text="@string/hello"
/><ListViewandroid:id="@+id/contactList"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_above="@id/textView"
/></RelativeLayout>
MainActivity class:
@OverridepublicvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ListView listView = (ListView) findViewById(R.id.contactList);
String[] values = newString[] { "Android", "iPhone", "WindowsMobile",
"Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X",
"Linux", "OS/2" };
// First parameter - Context// Second parameter - Layout for the row// Third parameter - ID of the TextView to which the data is written// Forth - the Array of dataArrayAdapter<String> adapter = newArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, android.R.id.text1, values);
// Assign adapter to ListView
listView.setAdapter(adapter);
}
Now when you put things inside the listView
it should not "push" the button or the textView
down.
Solution 2:
Firstly you have to set a linear layout in a main relative layout and set its gravity bottom
<RelativeLayoutandroid:width = "fill..."android....><LinearLayoutandroid:gravity="bottom"android:id="@+id/linear1"android:layout_alignParentBottom="true"><Button/></LinearLayout><ListViewandroid:layout_above="@id/linear"/>
Solution 3:
android:layout_weight="1"
delete it.
if you are not express 'android:layout_weightSum' on over level that cotains some components are express 'android:layout_weight' but also component that contain 'android:layout_weight="1"' code is exactly change size to fullscreen.
(i'm sorry, i can't speak english very well....)
- android:layout_weight="1" is wrong
- android:layout_weight="1" delete it
- Or use android:layout_weightSum first.
Post a Comment for "Displaying The Button At The End Of The Listview With Linear Layout"