2016-09-08 53 views
0

我創建波紋管佈局:LinearLayout中的重力 - android?

<?xml version="1.0" encoding="utf-8"?> 
<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/relativeStart" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/back" 
    tools:context=".SongsActivity"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@drawable/header" 
     android:orientation="vertical"> 

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

      <ImageButton 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:background="@null" 
       android:src="@drawable/felesh_m" /> 

      <LinearLayout 
       android:layout_width="wrap_content" 
       android:layout_height="match_parent" 
       android:layout_gravity="center_horizontal|center_vertical" 
       android:gravity="center_horizontal|center_vertical" 
       android:orientation="vertical"> 

       <ImageButton 
        android:id="@+id/imbCenter" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="center_horizontal|center_vertical" 
        android:background="@null" 
        android:src="@drawable/hosein_hlarge" /> 
      </LinearLayout> 

      <ImageButton 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:background="@null" 
       android:src="@drawable/felesh_m" /> 
     </LinearLayout> 

     <android.support.v7.widget.RecyclerView 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="4" /> 
    </LinearLayout> 
</RelativeLayout> 

參見下文圖片:

enter image description here

+0

查看我的回答如下,讓我知道,如果你面對的任何問題。 –

回答

2

更改您的佈局,因爲這。你不需要採取多個Linear Layouts。因爲這對性能不利。所以我已經將它改爲Linear Layout以及一些Weight屬性。

<?xml version="1.0" encoding="utf-8"?> 
<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/relativeStart" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/common_ic_googleplayservices"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@drawable/common_ic_googleplayservices" 
     android:orientation="vertical"> 

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

      <ImageButton 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="0.50" 
       android:background="@null" 
       android:src="@drawable/common_ic_googleplayservices" /> 


      <ImageButton 
       android:id="@+id/imbCenter" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="2" 
       android:background="@null" 
       android:src="@drawable/common_ic_googleplayservices" /> 

      <ImageButton 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="0.50" 
       android:background="@null" 
       android:src="@drawable/common_ic_googleplayservices" /> 
     </LinearLayout> 

     <android.support.v7.widget.RecyclerView 
      android:layout_width="match_parent" 
      android:layout_height="0dp" 
      android:layout_weight="4" /> 
    </LinearLayout> 
</RelativeLayout> 

enter image description here

+0

@ jaydroider.Thnaks很多。 –

+1

RelativeLayout或第一個LinearLayout不是必需的。我會刪除兩個LinearLayouts,因爲所有可以通過使用一個RelativeLayout來完成。爲您的用戶界面提供更快的響應速度 –

+1

@Rotwang先生,他已經在垂直方向上使用了「Recycler View」,然後他想在水平方向再添加3張圖像,這就是爲什麼他可能會這樣設置。 –