1

我試圖讓圖像和列表在同一'滾動'(我不知道怎麼說)。我的基本(垂直)佈局是:列表和圖像在同一個滾動視圖

  • 的TextView

  • ImageView的

  • 的ListView

我試圖讓滾動彷彿圖像是一個列表項目本身。所以textview必須保留在頂部,其他所有內容都必須在它下面滾動。

此刻,我有以下代碼:

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

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="@color/app_purple" 
    android:orientation="vertical" > 

    <TextView 
     android:id="@+id/about_app_label" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_horizontal" 
     android:padding="15dp" 
     android:text="@string/about_app_label" 
     android:textColor="@color/background" 
     android:textSize="20dp" 
     android:textStyle="bold" /> 

     <ImageView 
      android:id="@+id/app_logo" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:adjustViewBounds="true" 
      android:src="@drawable/logo" /> 

</LinearLayout> 

<ListView 
    android:id="@+id/information_list" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@color/background" 
    android:divider="@drawable/listdivider" 
    android:dividerHeight="1dp" 
    android:fadingEdge="none" > 

    <!-- Preview: [email protected]/row --> 
</ListView> 

任何幫助將不勝感激!

編輯

爲ListView的自定義行佈局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:background="@color/listview" 
android:orientation="horizontal" 
android:padding="4dip" > 

<ImageView 
    android:id="@+id/list_icon" 
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent" 
    android:adjustViewBounds="true" 
    android:layout_marginRight="5dp" 
    android:contentDescription="@string/icon_content_description" /> 

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" > 

    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" > 

     <TextView 
      android:id="@+id/list_label" 
      android:layout_width="200dp" 
      android:layout_height="wrap_content" 

      android:maxLines="1" 
      android:paddingBottom="5dp" 
      android:paddingTop="5dp" 
      android:textColor="@color/result_label" 
      android:textStyle="bold" /> 

     <TextView 
      android:id="@+id/list_count" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentTop="true" 
      android:layout_toRightOf="@+id/list_label" 
      android:ellipsize="end" 
      android:gravity="center_vertical" 
      android:maxLines="1" 
      android:textColor="@color/text" /> 
    </RelativeLayout> 

    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" > 

     <TextView 
      android:id="@+id/list_result" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="center_vertical" 
      android:textColor="@color/text" 
      android:textColorLink="@color/app_purple" /> 

     <ProgressBar 
      android:id="@+id/list_progress" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentTop="true" 
      android:gravity="center_vertical" 
      android:visibility="gone" /> 
    </RelativeLayout> 
</LinearLayout> 

回答

2

你將有一個垂直LinearLayout拿着固定TextViewListView。您的ImageView將作爲ListView的標題,通過addHeaderView()添加。標題儘管有其名稱,但會滾動顯示ListView的內容。

+0

謝謝,這正是尋找的東西。這是你第二次幫助我完成這個項目,第一次是通過你的一本書:)。 – Meatje 2012-03-04 23:40:51

1

進行自定義列表視圖,你需要創建一個single_list_item.xml文件來安排你想要的一切例如滾動旁邊有描述文字的圖像。您還需要在Xml文件上添加ListView,以便程序可以處理該視圖。而他們,你可以使用一個適配器來處理你的java文件中的所有內容。並且該列表將顯示在文本的底部。

有是如何做到這一點here

+0

我已經有一個listView的自定義行佈局。但我沒有看到使imageView佔用整行的可能性。或者是否可以使用不同的佈局來實現一行?我已經使用row.xml代碼更新了我的帖子。儘管感謝您的幫助。 – Meatje 2012-03-04 22:54:10

+0

爲什麼不將ImageView添加到row.xml文件並將其繪製在文本的頂部......也可以在eclipse下佈局的圖形視圖中查看每行將如何看到圖像。 – 2012-03-04 23:05:10

0

目前還不清楚到底是什麼你想要做一個很好的例子。 ScrolView只能有一個孩子。所以我想你應該把ImageView和Listview放在一個LinearLayout中。 但任何方式 - 將一個列表視圖放在ScrollView中是一個壞主意 - 操作系統現在將如何滾動? ListItem或整個列表。如果你能更具體的 - 我可以嘗試幫助更多...

+0

我想我必須把imageView作爲listview中的第一行,但我已經有了一個不允許的自定義行佈局,我將自定義row.xml添加到了原始文章中。我認爲我最好的選擇是將imageView作爲一行添加到listView中,但我不知道如何使用當前的row.xml佈局來實現。 – Meatje 2012-03-04 23:07:08