2016-06-28 19 views
0

で複数のImageButtonsを揃える:アンドロイド - 私は私のAndroidアプリケーションでは、次のレイアウトを作成しようとしていますRelativeLayout

<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:orientation="vertical" 
    tools:context=".MainActivity"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:background="@color/colorPrimary" /> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:background="@android:color/white" /> 

</LinearLayout> 

enter image description here

私は2つの別々のレイアウトを持っているために、このコードを持っています一番下のレイアウトはImageButtonの複数のページがあるので、ViewPagerになります。私の質問は、どのようにボタンを各レイアウト/フラグメントに完全に合わせることができますか?

答えて

1
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:background="@android:color/darker_gray" /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1" 
     android:background="@android:color/white" 
     android:orientation="vertical"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" 
      android:orientation="horizontal"> 

      <ImageButton 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:src="@android:drawable/btn_star_big_on" /> 

      <ImageButton 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:src="@android:drawable/btn_star_big_on" /> 

     </LinearLayout> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" 
      android:orientation="horizontal"> 

      <ImageButton 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:src="@android:drawable/btn_star_big_on" /> 

      <ImageButton 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:src="@android:drawable/btn_star_big_on" /> 

     </LinearLayout> 


    </LinearLayout> 

</LinearLayout>  

ネストされたレイアウトがパフォーマンスに悪い場合でも、この種類のネストは最小限であるため、パフォーマンスの差はごくわずかです。

関連する問題