当前位置: 动力学知识库 > 问答 > 编程问答 >

Android: ListView disappears in landscape view

问题描述:

I'm basically trying to create a listview of items underneath of a button that's on the top of my screen. I currently have my listview overwritten with 4 textviews and it all works great until I make the app landscape. This all works as long as it's portrait.

Here is my main activity

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="horizontal" >

<Button

android:id="@+id/button1"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_gravity="center_horizontal"

android:gravity="center"

android:text="Pull Pipeline Grid"

android:onClick="onClick"/>

<ListView

xmlns:android="http://schemas.android.com/apk/res/android"

android:id="@+id/listview"

android:layout_width="match_parent"

android:layout_height="wrap_content"

></ListView>

Here is my row.xml which is my listview override xml

<?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="?android:attr/listPreferredItemHeight"

android:padding="6dip"

android:layout_alignParentBottom="true">

<TextView

android:id="@+id/textView"

android:layout_width="fill_parent"

android:layout_height="26dip"

android:layout_alignParentTop="true"

android:layout_alignParentRight="true"

android:ellipsize="marquee"

android:singleLine="true"

android:text="Description"

android:textSize="12sp" />

<TextView

android:id="@+id/textView2"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_below="@id/textView"

android:layout_alignParentRight="true"

android:layout_alignParentBottom="true"

android:layout_alignWithParentIfMissing="true"

android:gravity="center_vertical"

android:text="Example application"

android:textSize="16sp" />

<TextView

android:id="@+id/textView3"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_below="@id/textView2"

android:layout_alignParentRight="true"

android:layout_alignParentBottom="true"

android:layout_alignWithParentIfMissing="true"

android:gravity="center_vertical"

android:text="Hello"

android:textSize="16sp" />

<TextView

android:id="@+id/textView4"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_below="@id/textView3"

android:layout_alignParentRight="true"

android:layout_alignWithParentIfMissing="true"

android:gravity="center_vertical"

android:text="World"

android:textSize="16sp" />

This could be a very simple fix, but i'm new to android development and I dont understand the piece i'm missing. Here's the outcome i want

网友答案:

Try this change orientation of LinearLayout to vertical like this

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
   android:layout_height="wrap_content"
    android:orientation="vertical" >
    <Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="Pull Pipeline Grid"
android:onClick="onClick"/>

   <ListView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
></ListView>

Hope it helps. Refer here for more ListView Samples http://coderzpassion.com/android-listview-with-image-and-text/

分享给朋友:
您可能感兴趣的文章:
随机阅读: