开发者

Android - how to get ListView to line up underneath Text View

开发者 https://www.devze.com 2023-02-06 16:10 出处:网络
I am attempting to put a ListView beneath a Text View in an Android App. However, the first line of the ListView shows up on the same line as the TextView. How do I get this to move underneath?

I am attempting to put a ListView beneath a Text View in an Android App. However, the first line of the ListView shows up on the same line as the TextView. How do I get this to move underneath?

Here is the layout:

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

    <TextView android:id="@+id/android:question"
          android:layout_width="w开发者_运维问答rap_content"
            android:layout_height="wrap_content"
            android:text="@string/dummy_question" />    
    <ListView android:id="@+id/android:list"
          android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
    <TextView android:id="@+id/android:empty"
          android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/no_notes"/>

</LinearLayout>


I think at first look prob. is only that in linearlayout put


android:orientation=vertical


it will solve ur prob.


Try using a TableLayout. Example. Good luck.


I see two issues. First, as chirag mentioned, you need to set the ListView orientation. Second, a listView cannot 'wrap content' for height. What would it wrap to? One row, two? Basically, a listView has no idea how tall you want it to be. Try this:

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

<TextView android:id="@+id/android:question"
      android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/dummy_question" />    
<ListView android:id="@+id/android:list"
      android:layout_width="wrap_content"
        android:layout_height="0px" android:layout_weight="1" />
<TextView android:id="@+id/android:empty"
      android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/no_notes"/>
</LinearLayout>
0

精彩评论

暂无评论...
验证码 换一张
取 消