2013-07-03 14 views
12

Ich habe folgendes Layout:Android relativ Layout align Eltern rechts

<?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:id="@+id/test_ll" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@drawable/background" 
android:orientation="vertical" > 

<RelativeLayout 
    android:id="@+id/main_layPanelCircle" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center_vertical|center_horizontal" 
    android:layout_marginLeft="10dp" 
    android:layout_marginRight="10dp" 
    android:layout_marginTop="15dp" 
    android:background="@drawable/main_panel_a" 
    android:orientation="vertical" 
    android:padding="10dp" > 

    <ImageView 
     android:id="@+id/main_imgBreachAlert" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginRight="5dp" /> 

    <Button 
     android:id="@+id/main_btnMap" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:background="@null" 
     android:drawableTop="@drawable/icon_find" 
     android:text="@string/main_locate" 
     android:textColor="@android:color/white" 
     android:textSize="10sp" /> 

    <LinearLayout 
     android:id="@+id/main_llPanelCycleMiddle" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/main_btnMap" 
     android:layout_centerInParent="true" 
     android:orientation="horizontal" > 

     <Button 
      android:id="@+id/main_btnLeft" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="@null" 
      android:drawableTop="@drawable/icon_call" 
      android:text="@string/main_call" 
      android:textColor="@android:color/white" 
      android:textSize="10sp" 
      android:visibility="visible" /> 

     <Button 
      android:id="@+id/main_btnEmergency" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="@null" 
      android:drawableTop="@drawable/icon_emergency" 
      android:scaleType="center" 
      android:text="@string/main_emergency" 
      android:textColor="@android:color/white" 
      android:textSize="9sp" 
      android:textStyle="bold" /> 

     <Button 
      android:id="@+id/main_btnRight" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="@null" 
      android:drawableTop="@drawable/icon_store" 
      android:text="@string/main_store" 
      android:textColor="@android:color/white" 
      android:textSize="10sp" /> 
    </LinearLayout> 

    <Button 
     android:id="@+id/main_btnMore" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/main_llPanelCycleMiddle" 
     android:layout_centerHorizontal="true" 
     android:background="@null" 
     android:drawableTop="@drawable/icon_more" 
     android:text="@string/main_more" 
     android:textColor="@android:color/white" 
     android:textSize="10sp" /> 
</RelativeLayout> 

</LinearLayout> 

Wenn ich main_imgBreachAlert android gesetzt: layout_alignParentLeft = "true" eveerything OK ist (linkes Bild), aber wenn ich stelle es nach rechts Mine relativ Layout Strecken (linkes Bild):

http://i.imgur.com/uDJqF0k.jpg?1

könnten Sie bitte beraten, wie könnte ich dieses Problem beheben.

Thnx

+0

Passen Sie es links und rechts gleichzeitig an die Eltern an? Wenn dies der Fall ist, zwingt es das Elternelement, den Wrap_Content zu überschreiben (als das kleinere von zwei Übeln, die andere Option wäre, etwas anderes im Layout auf die gleiche Größe zu verkleinern). –

+0

Haben Sie eine Antwort auf Ihre Frage gefunden? Iam läuft in genau das gleiche Problem – Snake

Antwort

26

Versuchen android:layout_centerInParent="true" und entfernen Sie das alignParentLeft Attribut, wenn Sie das Bild in Ihrem Layout zentriert werden soll.

Wenn Sie nur nach rechts ausrichten möchten, verwenden Sie einfach android:layout_alignParentRight="true".

<ImageView 
    android:id="@+id/main_imgBreachAlert" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:layout_marginRight="5dp" /> 
+2

Ich möchte das Bild auf der rechten Seite nicht zentriert setzen. – Damir

+1

Verwenden Sie dann nur android: alignParentRight = "true" und entfernen Sie das alignParentLeft-Attribut. – Flynn81

+2

Wenn ich alignParentRight als stretch Elternteil, in dem dieses Steuerelement ist in. Ich dünn, dass meine Vorgehensweise falsch ist. Ich möchte tatsächlich Layout-Hintergrund festlegen und Layout um diesen Hintergrund wickeln und als andere Steuerelemente innerhalb dieses Layouts setzen, aber es sollte um Hintergrundbild gewickelt bleiben. Wenn das Sinn macht. – Damir

Verwandte Themen