2010-12-07 11 views
0

ここに私のコードです。私もTableLayoutでこれを試しました。私が何をしているかにかかわらず、すべてが左に並んでいます。これを望みます(通常のユースケースと思われるもの)。同じ親に左右のビューを並べる最良の方法は?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/actionbar" 
    android:orientation="horizontal" 
    android:background="@layout/lightblue_gradient" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 
    <ImageView 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:layout_margin="3dip" 
     android:gravity="left" 
     android:src="@drawable/logo" /> 

    <ImageView 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:gravity="right" 
     android:src="@drawable/ic_menu_search" /> 
</LinearLayout> 

答えて

1

RelativeLayoutをお試しください:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/actionbar" 
    android:orientation="horizontal" 
    android:background="@layout/lightblue_gradient" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 
    <ImageView 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:layout_alignParentRight="true" 
     android:src="@drawable/logo" /> 

    <ImageView 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:layout_alignParentRight="true" 
     android:src="@drawable/ic_menu_search" /> 
</RelativeLayout> 
+0

1 @andreas。これは私の知るべき最善の方法です。 – Varun

関連する問題