2010-03-30 65 views
0

我的應用程序顯示一個項目列表,每一行是一個項目標題,形象的旁白,該行保留的文字空間70%,而圖像的30%。想象一下iPhone應用程序商店的外觀。爲此推薦哪個視圖/佈局組合?android:我應該使用哪個視圖來顯示文本和圖像?

我用Google搜索,發現這篇文章:

http://www.curious-creature.org/2009/02/22/android-layout-tricks-1/

請問這個觀點聽起來好?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="?android:attr/listPreferredItemHeight" 

android:padding="6dip"> 

<ImageView 
    android:id="@+id/icon" 

    android:layout_width="wrap_content" 
    android:layout_height="fill_parent" 

    android:layout_alignParentTop="true" 
    android:layout_alignParentBottom="true" 
    android:layout_marginRight="6dip" 

    android:src="@drawable/icon" /> 

<TextView 
    android:id="@+id/secondLine" 

    android:layout_width="fill_parent" 
    android:layout_height="26dip" 

    android:layout_toRightOf="@id/icon" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentRight="true" 

    android:singleLine="true" 
    android:ellipsize="marquee" 
    android:text="Simple application that shows how to use RelativeLayout" /> 

<TextView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 

    android:layout_toRightOf="@id/icon" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentTop="true" 
    android:layout_above="@id/secondLine" 
    android:layout_alignWithParentIfMissing="true" 

    android:gravity="center_vertical" 
    android:text="My Application" /> 

回答

1

如果由「iPhone應用程序商店的樣子」,你的意思是「幾乎每一個單一的名單在那裏」(好吧,至少據我可以通過描述來判斷,從未真正見過的iPhone應用程序商店),似乎只有一種方法可行。 '理想'的解決方案是使用RelativeLayout,因爲它允許你在圖像旁邊有兩行文本,而不需要複雜的版面結構。然而,正如你可以在this questionthis other question看,似乎有一些問題與。因此,後退是使用水平的LinearLayout,並在其中嵌套第二個垂直LinearLayout,如果您需要多行文本。查看這些帖子,瞭解有關LinearLayout應該是什麼樣子的更多細節。

注:我假設你知道如何使用一個ListView。如果你不知道ListView是如何工作的,那麼我推薦this article作爲一個好的開始。這有點舊,但還是不錯的。只要確保你閱讀its sequels,這也解釋瞭如何使用convertView優化。

編輯:對於任何人讀這篇文章,這裏是一個tutorial on Lists有更好的格式,使之更易於閱讀。

+0

感謝我編輯原來的職位。你可以看一下嗎? – Yang 2010-03-30 20:31:10

+0

這就是我在我所鏈接的兩個問題中討論的帖子。 (好的,我在Android官方博客上將其鏈接到它,而不是他個人的博客)。但是,我們中的一些人試圖讓它工作,並沒有設法這樣做。它看起來很棒,直到你把它放在一個ListView中,然後出於一些無法解釋的原因,它不能正確加載。如果你能讓它看起來不錯,讓我們知道! – 2010-03-30 20:41:04

+0

我已經列入了新的錯誤,你可以看看我的新帖子:http://stackoverflow.com/questions/2549585/android-failed-to-setcontentview-when-switching-to-listactivity – Yang 2010-03-31 01:06:12

1

的ListView通過該行自定義佈局。在創建ListAdapter(SimpleAdapter/ArrayAdapter)時,您可以在構造函數中傳入佈局。它真的很容易,如果圖像總是相同的,但如果圖像會有所不同,您將需要重寫getView方法來創建行的視圖。

相關問題