Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Aligning ImageView to right of the layout android

Tags:

I have an layout

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"     android:orientation="horizontal"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:background="#FFFFFF">      <TextView android:id="@+id/groupname"          android:paddingLeft="50px"          android:textSize="16px"          android:background="#FFFFFF"          android:textColor="#000000"          android:textStyle="normal"          android:layout_width="wrap_content"          android:layout_height="50px"/>      <ImageView              android:layout_width="match_parent"              android:layout_height="wrap_content"              android:layout_gravity="right"              android:layout_marginRight="6dp"              android:background="#ffffff"               android:src="@drawable/sort"/>  </LinearLayout> 

Rendering like this presentlyI want to render like this

Rendering is happening now like in first image but I wanted to render like in second image fully right aligned. any help would be useful.

Looking forward to your reply. thanks.

like image 269
Mukunda Avatar asked Feb 21 '12 07:02

Mukunda


People also ask

What is the default orientation of a LinearLayout?

When the orientation of a LinearLayout is unspecified, it is using the default, which is horizontal . Should the layout be a column or a row? Use "horizontal" for a row, "vertical" for a column. The default is horizontal.

Can ImageView be clickable?

Using clickable imagesYou can turn any View , such as an ImageView , into a button by adding the android:onClick attribute in the XML layout. The image for the ImageView must already be stored in the drawable folder of your project.

Which attribute is used to set an image in ImageView in Android?

An ImageView control is used to display images in Android applications. An image can be displayed by assigning it to the ImageView control and including the android:src attribute in the XML definition of the control. Images can also be dynamically assigned to the ImageView control through Java code.


2 Answers

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"     android:orientation="horizontal"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:background="#FFFFFF">      <TextView android:id="@+id/groupname"          android:paddingLeft="50dp"          android:textSize="16dp"          android:textColor="#000000"          android:textStyle="normal"          android:layout_width="fill_parent"          android:layout_height="50dp"          android:layout_weight="0.9"          android:background="@color/black"/>      <ImageView              android:layout_width="wrap_content"              android:layout_height="wrap_content"              android:layout_gravity="right"              android:background="#ffffff"               android:src="@drawable/checkin"              android:layout_weight="0.1"/>  </LinearLayout> 

Try this, hope this will help.

Prview1enter image description here

like image 88
Triode Avatar answered Oct 09 '22 07:10

Triode


use android:layout_weight="1" for text view

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"   android:orientation="horizontal"   android:layout_width="fill_parent"   android:layout_height="fill_parent"   android:background="#FFFFFF">    <TextView android:id="@+id/groupname"      android:paddingLeft="50px"      android:textSize="16px"      android:layout_weight="1"      android:background="#FFFFFF"      android:textColor="#000000"      android:textStyle="normal"      android:layout_width="0dp"      android:layout_height="50px"/>  <ImageView          android:layout_width="wrap_content"          android:layout_height="wrap_content"          android:layout_gravity="right"          android:layout_marginRight="6dp"          android:background="#ffffff"           android:src="@drawable/sort"/>  </LinearLayout> 
like image 32
RajaReddy PolamReddy Avatar answered Oct 09 '22 08:10

RajaReddy PolamReddy