0

I'm trying to create a android layout like:

[####EditText###][Button]

[####listview#####]

For that i'm using weight, but the following xml is giving me something very strang like:

[editText][button][ListView]

Someone know why?

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:background="@drawable/background" android:weightSum="10" > <EditText android:id="@+id/nova_lista" android:inputType="text" android:layout_height="wrap_content" android:layout_width="0dp" android:layout_weight="9" android:hint="@string/new_list_hint"> </EditText> <Button android:id="@+id/nova_lista_botao" android:layout_height="wrap_content" android:layout_width="0dp" android:layout_weight="1" android:text="@string/new_list"/> <ListView android:id="@+id/list_of_lists" android:layout_width="fill_parent" android:layout_height="wrap_content" > </ListView> </LinearLayout> 

3 Answers 3

6

You are using android:orientation="vertical"

and you are specifying android:layout_width equal to 0dp.

For vertical layout layout_height should be 0 dp and for Horizontal layout layout_width should be 0 dp if you are using weight in LinearLayout.

Put EditText and Button in separate Horizontal Layout. Use below code

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:background="@drawable/background" > <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:weightSum="10" > <EditText android:id="@+id/nova_lista" android:inputType="text" android:layout_height="wrap_content" android:layout_width="0dp" android:layout_weight="9" android:hint="@string/new_list_hint"> </EditText> <Button android:id="@+id/nova_lista_botao" android:layout_height="wrap_content" android:layout_width="0dp" android:layout_weight="1" android:text="@string/new_list"/> </LinearLayout> <ListView android:id="@+id/list_of_lists" android:layout_width="fill_parent" android:layout_height="wrap_content" > </ListView> </LinearLayout> 
Sign up to request clarification or add additional context in comments.

Comments

0

Maybe this is what you are looking for:

<?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" android:orientation="vertical" android:background="#ffffff" > <EditText android:id="@+id/nova_lista" android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_toLeftOf="@id/nova_lista_botao" android:inputType="text" android:hint="something"> </EditText> <Button android:id="@+id/nova_lista_botao" android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignParentRight="true" android:text="Hello"/> <ListView android:id="@+id/list_of_lists" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_below="@id/nova_lista" > </ListView> </RelativeLayout> 

enter image description here

Hope that helps.

Comments

0

1.Set your main layout is RelativeLayout

2.Create LinarLayout and move EditText and Button to LinerLayout

3.Set LinerLayout is "@+id/top_layout" and set listview is

android:layout_below="@+id/top_layout"

<?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" android:orientation="vertical" android:background="@drawable/background" android:weightSum="10" > <LinearLayout android:id="@+id/top_layout" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <EditText android:id="@+id/nova_lista" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="9" android:hint="@string/new_list_hint" android:inputType="text" > </EditText> <Button android:id="@+id/nova_lista_botao" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="@string/new_list" /> </LinearLayout> <ListView android:id="@+id/list_of_lists" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/top_layout" > </ListView> </RelativeLayout> 

Comments