smartmouse
smartmouse

Reputation: 14404

How to put an element on the right of some rows in RelativeLayout?

i created this layout for my list rows:

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

    <LinearLayout
        android:id="@+id/viewNameM"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/orange_button_pressed" >

        <TextView
            android:id="@+id/nameUser"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:gravity="center_horizontal"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#f6911e"
            android:textStyle="bold" />
    </LinearLayout>

    <RelativeLayout
        android:id="@+id/viewDetails1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/viewNameM"
        android:layout_marginTop="10dp"
        android:layout_marginLeft="10dp" 
        android:layout_marginRight="10dp" >

        <ImageView
            android:id="@+id/arrow"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/catUser"
            android:layout_alignParentRight="true"
            android:layout_alignTop="@+id/catUser"
            android:contentDescription="@string/arrowS"
            android:src="@drawable/arrow" />

        <TextView
            android:id="@+id/catUser"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_marginBottom="3dp"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#4a4c4d" />

        <RatingBar
            android:id="@+id/ratingUser"
            style="?android:attr/ratingBarStyleSmall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignRight="@+id/arrow"
            android:layout_marginRight="20dp"
            android:layout_marginBottom="3dp"
            android:layout_alignBottom="@+id/catUser"
            android:indeterminate="false"
            android:isIndicator="true"
            android:numStars="@integer/five"
            android:stepSize="0.1" />

    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/viewDetails2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/viewDetails1"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="10dp" 
        android:layout_marginRight="10dp" >

        <TextView
            android:id="@+id/cityUser"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:textStyle="bold"
            android:layout_marginBottom="3dp"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#4a4c4d" />

        <TextView
            android:id="@+id/distance"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:textAppearance="?android:attr/textAppearanceMedium" />

    </RelativeLayout>
</RelativeLayout>

Here is the output:

enter image description here

I would like to keep the arrow on the right of the rows, but i would to set it in the middle, like this:

enter image description here

I make several tries, but i cannot reach my goal. How to do that? Thank you in advance.

Upvotes: 0

Views: 508

Answers (3)

Fedor Kazakov
Fedor Kazakov

Reputation: 601

<?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="match_parent"
                android:background="#ffffff" >

    <LinearLayout
        android:id="@+id/viewNameM"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#cccccc" >

        <TextView
            android:id="@+id/nameUser"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="10dp"
            android:gravity="center_horizontal"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#f6911e"
            android:textStyle="bold" />
    </LinearLayout>

    <RelativeLayout
        android:id="@+id/viewDetails1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/viewNameM"
        android:layout_marginTop="10dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp" >

        <ImageView
            android:id="@+id/arrow"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:src="@drawable/chevron" />

        <TextView
            android:id="@+id/catUser"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:text="Hotel"
            android:layout_marginBottom="3dp"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#4a4c4d" />

        <RatingBar
            android:id="@+id/ratingUser"
            style="?android:attr/ratingBarStyleSmall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toLeftOf="@+id/arrow"
            android:layout_marginBottom="3dp"
            android:layout_alignBottom="@+id/catUser"
            android:indeterminate="false"
            android:isIndicator="true"
            android:numStars="5"
            android:stepSize="0.1" />

        <TextView
            android:id="@+id/cityUser"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@id/catUser"
            android:textStyle="bold"
            android:text="Roma"
            android:layout_marginBottom="3dp"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#4a4c4d" />

        <TextView
            android:id="@+id/distance"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toLeftOf="@+id/arrow"
            android:layout_below="@id/ratingUser"
            android:textColor="#4a4c4d"
            android:text="22km"
            android:textAppearance="?android:attr/textAppearanceMedium" />


    </RelativeLayout>


</RelativeLayout>

This is looks like you want.

Upvotes: 0

Marius
Marius

Reputation: 820

Just do it like you would in real life:

  1. Place caret on the right.
  2. Place rating on the left of the caret, below separating line.
  3. Place distance to the left of the caret, below rating.
  4. ...

Upvotes: 1

A-Droid Tech
A-Droid Tech

Reputation: 2321

Create layout of this type using Layout weight in LinnerLayout

Upvotes: 0

Related Questions