2016-06-30 8 views
1

Das ist, was ich will:Align Image nach oben rechts in einem Linearlayout

[Screenshot]

enter image description here

Hier ist, was ich getan habe:

<?xml version="1.0" encoding="utf-8"?> 
<merge xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_height="30dip" 
    android:background="@color/color" 
    android:orientation="vertical" > 


    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_margin="1dp" 
     android:background="@color/color" 
     android:orientation="horizontal"> 

     <View 
      android:id="@+id/divider" 
      android:layout_width="5dp" 
      android:layout_height="match_parent" 
      android:layout_gravity="center_vertical" 
      android:background="@color/grey" 
      android:gravity="center_vertical" /> 


    <LinearLayout 
     android:id="@+id/llayout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@color/color" 
     android:orientation="vertical" > 

     <TextView 
      android:id="@+id/label" 
      style="@style/some_style" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="left" 
      android:layout_marginLeft="8dp" 
      android:gravity="left" /> 

     <TextView 
      android:id="@+id/label2" 
      style="@style/some_style" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="left" 
      android:layout_marginLeft="8dp" 
      android:gravity="left" /> 

    </LinearLayout> 

    </LinearLayout> 

</merge> 

Ich habe getan, fast, aber das Problem ist, wie man das Bild rechts oben auf einem vertikalen linearen Layout ausrichten kann (siehe Screenshot).

Auch ich habe versucht mit Relative Layout, Bild kommt oben rechts, aber es schneidet meinen Text in der Textansicht.

Bitte machen:

Antwort

0

Sie es von layout_gravity Eigenschaft Imageview

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 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:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:orientation="vertical" 
    tools:context="com.fierbasedemo.MainActivity"> 

    <ImageView 
     android:id="@+id/tv_name" 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:layout_gravity="right" /> 
</LinearLayout> 
+0

es funktioniert der Trick aber am Anfang gibt es eine einzeilige Raum tht Ich will nicht. kannst du bitte helfen. Ich möchte ersten Text in der linken und Bild in der rechten – user6434454

+0

für das müssen Sie Relative Layout –

+0

alignParent = "links" für Textansicht und alignPatent = "rechts" für Bildansicht verwenden –

0

Nehmen android:layout_gravity="right" auf das übergeordnete Layout des Imageview

0

Sie müssen festlegen Image als Top-Element von Linearlayout setzen und geben seine Schwerkraft als:

android:layout_gravity="right|end" 

Wenn möglich, geben Sie diesem ImageView eine statische Größe.

2

Platz innerhalb LinearLayut andere RelativeLayout, die Ihre ImageView enthält und gelten für ImageView Attribut android:layout_alignParentRight="true"