Reputation: 2001
My layout looks like I want it to... up to the point that I get many items in the list and then the list covers the Edittext and Button elements.
I can't see what I have wrong. And when I set the ListView android:layout_height="fill_parent" it covered my buttons even when the list was empty.
This should be a pretty simple layout. I have spent over an hour messing with it.
Any help?
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical" >
<EditText
android:id="@+id/txt_editText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="@string/str_addSnippetHint" />
<Button
android:id="@+id/btn_addSnipet"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/addSnippet" />
</LinearLayout>
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@id/txt_editText"
android:layout_alignParentTop="true"
android:drawSelectorOnTop="false" />
Upvotes: 1
Views: 8229
Reputation: 11975
put this inside LinearLayout tag after Button
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:drawSelectorOnTop="false" />
Remove this line android:layout_above="@id/txt_editText"
And if you want to show listView above Button then Use Relative layout.And then set relativity
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<EditText
android:id="@+id/txt_editText"
android:layout_width="fill_parent" android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_height="wrap_content"
android:hint="@string/str_addSnippetHint" />
<Button android:id="@+id/btn_addSnipet" android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/addSnippet" />
<ListView android:id="@android:id/list"
android:layout_width="fill_parent" android:layout_above="@+id/btn_addSnipet"
android:layout_height="wrap_content" android:layout_above="@id/txt_editText"
android:layout_alignParentTop="true" android:drawSelectorOnTop="false" />
</RelativeLayout>
Upvotes: 4
Reputation: 8645
try this in place of your code
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical" >
<EditText
android:id="@+id/editText"
android:layout_width="fill_parent"
android:layout_alignParentLeft="true"
android:layout_height="wrap_content"
android:hint="edittext" />
<Button
android:id="@+id/btn_addSnipet"
android:layout_alignParentRight="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="button" />
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@id/txt_editText"
android:layout_alignParentTop="true"
android:drawSelectorOnTop="false" />
</LinearLayout>
Upvotes: 0
Reputation: 3926
trythis :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_alignParentBottom="true" android:orientation="vertical">
<ListView android:id="@android:id/list" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_alignParentTop="true"
android:drawSelectorOnTop="false" />
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_alignParentBottom="true"
android:layout_above="@id/list">
<EditText android:id="@+id/txt_editText"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_weight="1" android:hint="@string/str_addSnippetHint" />
<Button android:id="@+id/btn_addSnipet" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_weight="1"
android:layout_below="@id/txt_editText" android:text="@string/addSnippet" />
</RelativeLayout>
</RelativeLayout>
Upvotes: 0
Reputation: 8101
Add your ListView
inside the LinearLayout
instead of creating separate Layouts..
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical" >
<EditText
android:id="@+id/txt_editText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="@string/str_addSnippetHint" />
<Button
android:id="@+id/btn_addSnipet"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/addSnippet" />
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@id/txt_editText"
android:layout_alignParentTop="true"
android:drawSelectorOnTop="false" />
</LinearLayout>
Upvotes: 0