Android 覆盖整个屏幕的列表视图
我正在为聊天应用程序编写代码。我决定将消息放在列表视图中,然后使用文本视图让我的用户键入他想要发送的消息。 问题是,我的ListView覆盖了整个屏幕,即使它只包含2/3个元素,出于调试目的。在我的Android studio xml文件设计面板中,我确实看到了文本框,但当我尝试在Philical设备上启动时(在本例中,是一台10英寸的三星平板电脑),文本框并不存在 这是我的xml文件:Android 覆盖整个屏幕的列表视图,android,listview,android-listview,Android,Listview,Android Listview,我正在为聊天应用程序编写代码。我决定将消息放在列表视图中,然后使用文本视图让我的用户键入他想要发送的消息。 问题是,我的ListView覆盖了整个屏幕,即使它只包含2/3个元素,出于调试目的。在我的Android studio xml文件设计面板中,我确实看到了文本框,但当我尝试在Philical设备上启动时(在本例中,是一台10英寸的三星平板电脑),文本框并不存在 这是我的xml文件: <LinearLayout xmlns:android="http://schemas.android
<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" />
使用
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>
结果:
您可以使用这种方法 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 Studio的布局设计:
这来自设备nexus 7平板电脑:
在您的ListView元素上,用
android:layout\u height=“match\u parent”
替换android:layout\u height=“0”