Question

I have a listview with a custom adapter. I am trying to show subtext under an item. This is the xml I am using. The problem is that both TextView merge together. What can I do?

<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>
Was it helpful?

Solution

You can try it like below,

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

And your output will be as,

enter image description here

OTHER TIPS

use layout below and centerhorizontal for sub

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

I think, you have to remove the centerInParent from the sub.

Try this

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

Try this :

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

Try this

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

Hope it will work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top