2013-01-24 12 views
0

我想創建一個列表視圖,將有一個圖標和文本在一行和在另一行的子文本。 for exampleAndroid佈局圖標,文本和潛臺詞

我創建了一個自定義適配器來支持這個,我確實得到了一個圖像,一個文本和一個潛臺詞,但是每一個都在前一個之下。 例如 圖像0​​IMDB 帳戶

我的XML

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:padding="10dp"> 


    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="0" 
     android:orientation="vertical" > 

     <ImageView 
      android:id="@+id/imgIcon" 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      android:layout_marginBottom="5dp" 
      android:layout_marginRight="15dp" 
      android:layout_marginTop="5dp" 
      android:gravity="center_vertical" /> 

     <TextView 
      android:id="@+id/txtTitle" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_marginBottom="5dp" 
      android:layout_marginTop="5dp" 
      android:gravity="center_vertical" 
      android:textColor="#000000" 
      android:textSize="20sp" 
      /> 

     <TextView 
      android:id="@+id/subString" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      /> 
    </LinearLayout> 

</LinearLayout> 

我試圖將圖像和文本是第一線的佈局下,但隨後一切都很瘋狂,我也沒有再看文字或潛臺詞 有什麼想法?

謝謝

回答

1

這可能是更容易使用一個RelativeLayout的,但是這應該給你佈局,你的形象:

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:padding="10dp"> 

    <ImageView 
     android:id="@+id/imgIcon" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:layout_marginBottom="5dp" 
     android:layout_marginRight="15dp" 
     android:layout_marginTop="5dp" 
     android:gravity="center_vertical" /> 

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

     <TextView 
      android:id="@+id/txtTitle" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="5dp" 
      android:layout_marginTop="5dp" 
      android:gravity="center_vertical" 
      android:textColor="#000000" 
      android:textSize="20sp" /> 

     <TextView 
      android:id="@+id/subString" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" /> 

    </LinearLayout> 

</LinearLayout> 

或你想,你所描述的佈局,不顯示?無論如何,您發佈的佈局只能看到ImageView,因爲嵌套的LinearLayout具有垂直方向,並且ImageView的高度設置爲fill_parent ...因此,TextView從佈局的底部被推下。

+0

嗨,山姆,這結果與真正的高行只顯示圖標,不包含文本。任何想法爲什麼? 我想要得到一個佈局: 圖標IMDB在第一行,帳戶在第二行 – Quantico

+0

我更新了我的答案,你有最新的嗎?圖像有多大? – Sam

+0

嘿,我沒有看到你的更新,這似乎是大部分的伎倆。我認爲一旦我得到實際的圖像,它會更好看。當前圖像是一個favicon的佔位符。目前這是一張很小的1k圖片,因此似乎IMBD在圖像上稍微有點突出,但我認爲實際的圖像將解決這個問題。謝謝! – Quantico