2017-01-02 30 views
0

我想在第一行有3个图像按钮,在第二行有3个图像按钮。 我试图用相对和线性布局的组合来实现它,但是,不知何故,我结束了每行中的1个图像按钮,并且共有6行。无法对齐相对和线性布局中的图像按钮

有人可以帮我对齐第一行的3个图像框和第二行的3个框。

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="app.com.date.design.drawer.AddImagesFragment"> 

    <!-- TODO: Update blank fragment layout --> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:id="@+id/layout1" 
      android:baselineAligned="false" 
      android:orientation="vertical"> 

      <ImageButton 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       app:srcCompat="@drawable/common_full_open_on_phone" 
       android:id="@+id/image1" /> 

      <ImageButton 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       app:srcCompat="@drawable/common_full_open_on_phone" 
       android:id="@+id/image2" /> 

      <ImageButton 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       app:srcCompat="@drawable/common_full_open_on_phone" 
       android:id="@+id/image3" /> 

      <ImageButton 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       app:srcCompat="@drawable/common_full_open_on_phone" 
       android:id="@+id/image4" /> 

      <ImageButton 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       app:srcCompat="@drawable/common_full_open_on_phone" 
       android:id="@+id/image5" /> 

      <ImageButton 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       app:srcCompat="@drawable/common_full_open_on_phone" 
       android:id="@+id/image6" 
       android:layout_weight="0.05" /> 
     </LinearLayout> 

    </RelativeLayout> 

</FrameLayout> 

回答

1

尝试这个代码,

activity_main.xml中:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_main" 
    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"> 

    <LinearLayout 
     android:id="@+id/lin1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:weightSum="3"> 

     <ImageButton 
      android:id="@+id/image1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      app:srcCompat="@drawable/star2" /> 

     <ImageButton 
      android:id="@+id/image2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      app:srcCompat="@drawable/star1" /> 

     <ImageButton 
      android:id="@+id/image3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      app:srcCompat="@drawable/star3" /> 

    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/lin2" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/lin1" 
     android:orientation="horizontal" 
     android:weightSum="3"> 

     <ImageButton 
      android:id="@+id/image4" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      app:srcCompat="@drawable/star2" /> 

     <ImageButton 
      android:id="@+id/image5" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      app:srcCompat="@drawable/star1" /> 

     <ImageButton 
      android:id="@+id/image6" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      app:srcCompat="@drawable/star3" /> 

    </LinearLayout> 


</RelativeLayout> 

在此,I M安装截图,

enter image description here

希望它会帮助你。

+0

谢谢,它的工作 – user7327850

+0

欢迎:) :) :) :) –