2013-12-10 4 views
0

У меня есть listview с пользовательским адаптером. Я пытаюсь показать подтекст под элементом. Это xml, который я использую. Проблема в том, что оба TextView сливаются вместе. Что я могу сделать?Подтекст в Listview

<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 для toRightOf? Разве это не должно быть +? – Nfear

+0

Он работает с '+' также;) –

+0

Ну, похоже, что компилятор создает новый идентификатор, а Eclipse иногда перепутался с незаконными отбрасываниями. – Nfear

1

Думаю, вам нужно удалить центрInParent с вспомогательного устройства.

2

использование макета ниже и centerhorizontal для суб

<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> 

Надежда это будет работать.

Смежные вопросы