Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

<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!

like image 922
Hello World Avatar asked Dec 02 '25 04:12

Hello World


1 Answers

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>
like image 82
MilanNz Avatar answered Dec 03 '25 21:12

MilanNz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!