2012-02-21 13 views
18

que tiene un diseñoAlineando ImageView a la derecha de la distribución androide

<?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 presently I want to render like this

representación está sucediendo ahora como primera imagen, pero yo quería hacer como segunda imagen en totalmente alineado a la derecha. Cualquier ayuda sería útil.

Estamos ansiosos por su respuesta. gracias.

+1

Las personas que mencionan RelativeLayout como una solución más o menos tienen la solución correcta. Solo decirnos que no trabajamos no es ayudarnos a usted ni a nadie. – Maurice

+0

@Maurice gracias, pero para mí la respuesta no funcionó para RelativeLayout, eso es lo que respondí. – Mukunda

Respuesta

43
<?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> 

Prueba de esto, espero que esto ayude.

Prview1 enter image description here

+0

gracias. trabajando perfectamente – Mukunda

+0

Esto también se puede hacer sin el layout_weight en la vista de la imagen si la vista de la imagen tiene un ancho fijo. Simplemente configure el layout_weight en la vista de texto con un valor de 1. –

11

Utilice RelativeLayout como diseño principal.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent"> 

    <TextView android:id="@+id/groupname" 
       android:paddingLeft="50px" 
       android:textSize="16px" 
       android:textColor="#000000" 
       android:textStyle="normal" 
       android:layout_width="wrap_content" 
       android:layout_height="50px"/> 

    <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:layout_marginRight="6dp" 
      android:src="@drawable/ncc"/> 

</RelativeLayout> 
+1

gracias no funciona. – Mukunda

3
<?xml version="1.0" encoding="utf-8"?> 

<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:layout_alignParentRight="true" 
     android:src="@drawable/sort"/> 

+0

gracias, pero esto no está funcionando. – Mukunda

0

O bien utilizar RelativeLayout y establezca la propiedad de Vista de Texto de la siguiente manera:

layout_width=fill_parent 
layout_height=wrap_content 
left_of="@+id/imgView" 

y para ImageView

layout_width=wrap_content 
layout_height=wrap_content 
alignparentright=true 
+0

gracias no funciona. – Mukunda

23

uso androide: layout_weight = "1" para ver texto

<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> 
+0

gracias, esto es bueno! – AVEbrahimi

+0

¡Solución perfecta! – Surekha

0

se debe añadir tal cosa en XML ... para el objeto que desea alinear a la derecha ...

android:layout_alignParentRight="true" 
android:layout_marginRight="..dp" 
+0

gracias, pero esto no será posible ya que cómo establecería píxeles de densidad para diferentes pantallas. – Mukunda

+0

creando carpetas/diseños grandes,/xlarge,/pequeños para diferentes pantallas ... – timonvlad

3

Pruebe con RelativeLayout.

<?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" 
    android:background="#FFFFFF"> 

    <TextView 
     android:id="@+id/groupname" 
     android:layout_width="wrap_content" 
     android:layout_height="50px" 
     android:background="#FFFFFF" 
     android:paddingLeft="50px" 
     android:textColor="#000000" 
     android:textSize="16px" 
     android:textStyle="normal" /> 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:background="#ffffff" 
     android:src="@drawable/ic_launcher" /> 

</RelativeLayout> 
+0

gracias esto tampoco está funcionando. – Mukunda