Set one view to the right of another view

Description

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  va  2 s .  c  om
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);
    }
}




















Home »
  Android »
    Android UI »




UI Basics
Action Bar
Animation
Button
Canvas
CheckBox
Clock Date Picker
Dialog
EditText
Event
Fragment
Gesture
GridView
ImageView
Layout
ListView
Map
Menu
Model
OpenGL
ProgressBar
RadioButton
Spinner
Tab
TextView
Thread
Toast
Video
View
WebView