2016-06-28 15 views
0

Ich versuche, das folgende Layout in meinem Android-Anwendung zu machen:Android - mehrere ImageButtons in RelativeLayout ausrichten

enter image description here

Ich habe diesen Code zwei separate Layouts haben:

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

Die Unteres Layout wird eine ViewPager haben, weil es mehrere Seiten mit diesen ImageButton s geben wird, meine Frage ist, wie kann ich die Tasten perfekt in jedem Layout/Fragment ausrichten?

Antwort

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>  

Auch wenn verschachtelte Layouts für die Leistung schlecht sind, wäre der Leistungsunterschied hier vernachlässigbar, da diese Art der Verschachtelung minimal ist.

Verwandte Themen