Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Layout File - Positioning Item to Right of Another Item (Android)

I'm trying to position one item in a RelativeLayout to the right of another. In the example below I want the "," to be placed to the right of the description field. However the problem is it puts the comma on the first line next to the name field. Can anyone help?

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal"
    android:padding="10sp">
    <TextView 
        android:id="@+id/name"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" />
    <TextView
        android:id="@+id/description"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/name" />
    <TextView
        android:id="@+id/descriptioncomma"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text=", "
        android:layout_toRightOf="@id/description" />
like image 547
GuybrushThreepwood Avatar asked Sep 05 '11 08:09

GuybrushThreepwood


2 Answers

Try this code, it should work: Button used layout_toRightOf attribute with id of Textview widget.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal"
    android:padding="10sp">
    <TextView 
        android:id="@+id/name" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" />
    <TextView
        android:id="@+id/description" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/name" />
    <TextView
        android:id="@+id/descriptioncomma" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text=","
        android:layout_below="@id/name"
        android:layout_toRightOf="@id/description" />
</RelativeLayout>

In Both TextView you add text and than check it.

OK

like image 63
Mitesh Jain Avatar answered Nov 16 '22 00:11

Mitesh Jain


use this one

  <RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal"
    android:padding="10sp">
    <TextView 
    android:id="@+id/name"
    android:text="na"
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" />
    <TextView
    android:id="@+id/description"
    android:text="desc"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/name" />
    <TextView
    android:id="@+id/descriptioncomma"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text=", "
    android:layout_toRightOf="@id/description"
    android:layout_below="@id/name" />
            </RelativeLayout>
like image 32
Jyosna Avatar answered Nov 16 '22 01:11

Jyosna