2015-02-13 4 views
0

Я пишу код для чата. Я решил поместить сообщения в ListView, а затем иметь textView, чтобы мой пользователь напечатал сообщение, которое он хочет отправить. Проблема в том, что мой ListView охватывает весь экран, даже если он содержит только 2/3 элемента, что касается целей отладки. В моей панели дизайна студии Android для моего xml-файла я вижу TextBox, но когда я пытаюсь запустить на физическом устройстве (в данном случае 10-дюймовый планшет Samsung), TextBox не существует.ListView, охватывающий весь экран

Это мой XML-файл:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:orientation="vertical"> 

<ListView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/list_messages" 
    android:layout_weight="1"/> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/list_messages" > 

    <EditText android:id="@+id/id_edit_text_message" 
     android:inputType="textMultiLine" 
     android:text="Message" 
     android:ems="10" 
     android:layout_width="wrap_content" 
     android:layout_height="48dip" 
     android:layout_weight="10" /> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="48dip" 
     android:text="Send" 
     android:layout_weight="1"/> 

</LinearLayout></LinearLayout> 

И это мой ListView элемент, если это имеет значение ...

<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_height="wrap_content" 
android:minHeight="?android:attr/listPreferredItemHeight" 
android:layout_width="wrap_content" 
android:gravity="center_vertical" 
android:id="@+id/list_item_message" /> 
+2

На вашем ListView элемента заменить 'андроид: layout_height = "match_parent"' 'с андроида: layout_height = "0"' –

ответ

0

Используйте RelativeLayout в качестве корневого элемента вместо этого.

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <ListView 
     android:layout_above="@+id/layout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/list_messages"/> 

    <LinearLayout 
     android:layout_alignParentBottom="true" 
     android:id="@+id/layout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <EditText android:id="@+id/id_edit_text_message" 
      android:inputType="textMultiLine" 
      android:text="Message" 
      android:ems="10" 
      android:layout_width="wrap_content" 
      android:layout_height="48dip" 
      /> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="48dip" 
      android:text="Send"/> 
    </LinearLayout> 
</RelativeLayout> 

Результат:

Result

0

Ну вы можете использовать этот подход

XML файл:

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

    <ListView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/list_messages" 
     android:layout_weight="1"/> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/list_messages" > 

     <EditText android:id="@+id/id_edit_text_message" 
      android:inputType="textMultiLine" 
      android:text="Message" 
      android:ems="10" 
      android:layout_width="wrap_content" 
      android:layout_height="48dip" 
      android:layout_weight="10" /> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="48dip" 
      android:text="Send" 
      android:layout_weight="1"/> 

    </LinearLayout> 
</LinearLayout> 

Это от дизайна Android Студия макета: this is from the Android Studio Layout design

Это из связующего устройства 7 таблетки: this is from the device nexus 7 tablet