How to align ImageView and TextView left side and right side?

14,721

Add this for left side:

android:layout_alignParentLeft="true"

and this for right side:

android:layout_alignParentRight="true"

Copy this:

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:src="@drawable/imb"
    android:layout_alignParentLeft="true" />

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/imageView1"
    android:layout_alignParentRight="true"
    android:layout_alignTop="@+id/imageView1"
    android:layout_toRightOf="@+id/imageView1"
    android:background="@drawable/a"
    android:textAppearance="?android:attr/textAppearanceMedium" 
    android:layout_alignParentRight="true"/></RelativeLayout>
Share:
14,721
Hello World
Author by

Hello World

Student at New Horizon Institute, Nepal. Recently studying at Grade 8.

Updated on June 04, 2022

Comments

  • Hello World
    Hello World almost 2 years
    <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:gravity="end"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.ayush.ebook.MainActivity$PlaceholderFragment" >
    
    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:src="@drawable/imb" />
    
    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/imageView1"
        android:layout_alignParentRight="true"
        android:layout_alignTop="@+id/imageView1"
        android:layout_toRightOf="@+id/imageView1"
        android:background="@drawable/a"
        android:textAppearance="?android:attr/textAppearanceMedium" /></RelativeLayout>
    

    This is my layout. I have an ImageView on left side and TextView on right side. When I added ScrollView into it, the LinearLayout makes it up and down. I need a ScrollView as well as the way I aligned ImageView and TextView.

    Help me!

    • A.R.
      A.R. over 9 years
      set orientation of linear layout as android:orientation="horizontal" under your scroll view.
  • MilanNz
    MilanNz over 9 years
    If you want to use alignParentRight and left , it must be inside RelativeLayout. Put inside ScrollView one RelativeLayout and inside TextView and ImageView.