Android UI How to - Set one view to the right of another view








The following code shows how to Set one view to the right of another view.

Example

Main layout xml file

<?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">
    <TextView android:id="@+id/text_view_1"
        android:layout_width="150px"
        android:layout_height="100px"
        android:background="@android:color/darker_gray"
        />
    <TextView android:id="@+id/one"
        android:layout_width="150px"
        android:layout_height="100px"
        android:layout_toRightOf="@id/text_view_1"
        android:layout_centerVertical="true"
        android:background="@android:color/white"
        />
</RelativeLayout>

Main Activity Java code

import android.app.Activity;
import android.os.Bundle;
//ww  w.  ja  v  a2 s.  c o  m
public class MainActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);
    }
}