-2

this is my code:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >




<ListView
    android:id="@android:id/list"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center" >

</ListView>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="end"
     >

    <EditText
        android:id="@+id/editText2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0.73"
        android:ems="10" />

    <Button
        android:id="@+id/button1"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/enviar" />
</LinearLayout>

It is no running how I'd like. I need that the list view have an static size: all screen- the rest objects. And I need that the listview have in the top.

The problem is that if I put android:layout_height="match_parent" the listview's size is all screen. And if I put android:layout_height="wrap_content" the size is variable, and when I have a lot's of elements, the rest of object are not visible.

I need that the objects in the down of listview are always visibles. Some similar like a whatsapp conversation screen. Do you understand me? sorry for my bad English :)

user3235831
  • 45
  • 11

2 Answers2

1

You can have a RelativeLayout. Place the LinearLayout at the bottom. Place listview above LinearLayout.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

   <LinearLayout // this can be vartical or horizontal orientation depending on your need
       android:id="@+id/linearLayout1"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_alignParentBottom="true"
       android:layout_centerHorizontal="true"
       android:gravity="center"
       android:orientation="horizontal" >

      <EditText
        android:id="@+id/editText2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="10" />

    <Button
        android:id="@+id/button1"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="enviar" />


</LinearLayout>

    <ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/linearLayout1"
        android:layout_centerHorizontal="true" >

    </ListView>

</RelativeLayout>

Or Using single RelativeLayout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:text="Button" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:ems="10" >

        <requestFocus />
    </EditText>

    <ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/editText1"
        android:layout_alignEnd="@+id/button1"
        android:layout_alignParentRight="true" >

    </ListView>

</RelativeLayout>
Raghunandan
  • 132,755
  • 26
  • 225
  • 256
0

I would recommend using a relative layout that holds both the list view and your buttons. Set their layout weight attributes so that they take up the screen. Layout weight of 1 on one object and 7 on the other, for example, makes one take 7/8 of the screen while the other takes 1/8. If you need to be able to see more list view than that, put it in a scroll view.

AdamM
  • 162
  • 1
  • 8