2013-12-10 28 views
0

我有一個自定義適配器的列表視圖。我試圖在一個項目下顯示潛臺詞。這是我使用的xml。問題是兩個TextView合併在一起。我能做什麼?列表視圖中的潛臺詞

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 
    <TextView 
     android:id="@+id/tijd" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:paddingLeft="10dp" /> 
    <TextView 
     android:id="@+id/sub" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:layout_below="@id/tijd"/> 
    <ImageView 
     android:id="@+id/type" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_toLeftOf="@id/tijd" /> 
</RelativeLayout> 
+0

你想要它嗎? Apoorv是正確的...... – Triode

+0

我想要「tijd」在每行中居中並且圖像位於左側。我想要一個「tijd」下的潛臺詞。我以http://www.vogella.com/articles/AndroidListView/article.html爲指導。第1.3章 – Nfear

+0

@Nfear向我們展示如何使用圖片或快照 – Raghunandan

回答

2

,您可以嘗試像下面,

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

    <ImageView 
     android:id="@+id/type" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@drawable/ic_launcher" /> 

    <TextView 
     android:id="@+id/tijd" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="10dip" 
     android:layout_toRightOf="@+id/type" 
     android:text="abcde" /> 

    <TextView 
     android:id="@+id/sub" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/tijd" 
     android:layout_toRightOf="@+id/type" 
     android:text="abcd" /> 

</RelativeLayout> 

而你的輸出應該是,下面

enter image description here

+0

@ + id for toRightOf?不應該沒有+? – Nfear

+0

它也適用於'+'; –

+0

那麼編譯器似乎創建了一個新的id,Eclipse有時會被非法轉換搞砸。 – Nfear

1

我想,你必須從sub中刪除centerInParent。

2

利用佈局和centerhorizo​​ntal爲子

<TextView 
    android:id="@+id/sub" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/tijd" 
    android:centerHorizontal="true" 
    android:text="abcd" /> 
0

試試這個

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

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

     <ImageView 
      android:id="@+id/type" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/ic_launcher" /> 
    </LinearLayout> 

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

     <TextView 
      android:id="@+id/tijd" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="title" /> 

     <TextView 
      android:id="@+id/sub" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="subtitle" /> 
    </LinearLayout> 
</LinearLayout> 

0

試試這個:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" > 

<TextView 
    android:id="@+id/tijd" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_centerInParent="true" 
    android:text="Heading" /> 

<TextView 
    android:id="@+id/sub" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/tijd" 
    android:layout_centerInParent="true" 
    android:text="Subheading" /> 

<ImageView 
    android:id="@+id/type" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    android:layout_toLeftOf="@id/tijd" 
    android:background="@drawable/ic_launcher" /> 

0

試試這個

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

    <ImageView 
     android:id="@+id/type" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:src="@drawable/ic_launcher" /> 

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

     <TextView 
      android:id="@+id/tijd" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" 
      android:text="adad" /> 

     <TextView 
      android:id="@+id/sub" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" 
      android:text="adad" /> 
    </LinearLayout> 

</LinearLayout> 

希望它會工作。