2016-12-19 23 views
0

我正在添加一個頁腳到我的應用程序,該應用程序將包含三個帶圖片的按鈕。我想要類似於下面的視圖。我試過android:layout_gravity="right/left/center",但似乎不工作。對齊等於保證金的android佈局

enter image description here

下面是我的XML

<RelativeLayout 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" 
> 
<!-- Root element should wrap to parent size. --> 

<!-- Your view xml codes. --> 

<!--Bottom bar layout should be in root element. Parent should be Relative layout so that we can always align to parent bottom--> 
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:weightSum="4"> 

<LinearLayout 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:layout_gravity="left" 
    android:orientation="vertical" 
    > 


    <ImageView android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/brands" 

     /> 

    <TextView android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="brands" 

     /> 


</LinearLayout> 


<LinearLayout 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:orientation="vertical" 
    android:layout_gravity="center_horizontal" 
    > 


    <ImageView android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/stores" 

     /> 

    <TextView android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="brands" 

     /> 


</LinearLayout> 

<LinearLayout 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:layout_weight="1" 
    android:layout_gravity="right" 
    > 


    <ImageView android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/coupons" 

     /> 

    <TextView android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="brands" 

     /> 


</LinearLayout> 
</LinearLayout> 


</RelativeLayout> 

回答

2

你的父母LinearLayoutandroid:weightSum="4"和您的孩子LinearLayout所有總和爲3

因此改變你的父母LinearLayout weightSum android:weightSum="4"android:weightSum="3"

更新:

添加這樣

<RelativeLayout 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" 
> 
<!-- Root element should wrap to parent size. --> 

<!-- Your view xml codes. --> 

<!--Bottom bar layout should be in root element. Parent should be Relative layout so that we can always align to parent bottom--> 
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:weightSum="3"> 

<LinearLayout 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:orientation="vertical" 
    > 
    <ImageView android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/brands" 
     android:layout_gravity="center_horizontal" 
     /> 
    <TextView android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="brands" 
     android:layout_gravity="center_horizontal" 
     /> 
</LinearLayout> 
<LinearLayout 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:orientation="vertical" 
    > 
    <ImageView android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/stores" 
     android:layout_gravity="center_horizontal" 
     /> 
    <TextView android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="brands" 
     android:layout_gravity="center_horizontal" 
     /> 
</LinearLayout> 

<LinearLayout 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:layout_weight="1"> 
<ImageView android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/coupons" 
     android:layout_gravity="center_horizontal" 
     /> 
    <TextView android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="brands" 
     android:layout_gravity="center_horizontal"/> 
     </LinearLayout> 
    </LinearLayout> 
</RelativeLayout> 
+0

它確實使所有的圖像都適合屏幕。但我想要像張貼的照片。三幅圖像具有相同的邊緣。 。 –

+0

@ShivaAcharjee檢查我的代碼。 – Ironman

1

同樣重視佈局

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:orientation="horizontal" 
    android:layout_height="match_parent"> 
    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_weight="1" 
     android:gravity="center" 
     android:orientation="vertical" 
     android:layout_height="wrap_content"> 
     <ImageView 
      android:layout_width="24dp" 
      android:src="@android:drawable/ic_menu_rotate" 
      android:layout_height="24dp" /> 
     <TextView 
      android:layout_width="wrap_content" 
      android:text="@string/description" 
      android:layout_height="wrap_content" /> 
    </LinearLayout> 
    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_weight="1" 
     android:gravity="center" 
     android:orientation="vertical" 
     android:layout_height="wrap_content"> 
     <ImageView 
      android:layout_width="24dp" 
      android:src="@android:drawable/ic_menu_rotate" 
      android:layout_height="24dp" /> 
     <TextView 
      android:layout_width="wrap_content" 
      android:text="@string/description" 
      android:layout_height="wrap_content" /> 
    </LinearLayout> 
    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_weight="1" 
     android:gravity="center" 
     android:orientation="vertical" 
     android:layout_height="wrap_content"> 
     <ImageView 
      android:layout_width="24dp" 
      android:src="@android:drawable/ic_menu_rotate" 
      android:layout_height="24dp" /> 
     <TextView 
      android:layout_width="wrap_content" 
      android:text="@string/description" 
      android:layout_height="wrap_content" /> 
    </LinearLayout> 
</LinearLayout> 
2
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    > 

<LinearLayout 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:orientation="vertical"> 


<ImageView android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/brands" 
/> 

    <TextView android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="brands" 
/> 

</LinearLayout> 


<LinearLayout 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:orientation="vertical"> 


<ImageView android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/shops" 
/> 

    <TextView android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="shops" 
/> 

</LinearLayout> 


<LinearLayout 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:orientation="vertical"> 


<ImageView android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/coupons" 
/> 

    <TextView android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="coupons" 
/> 

</LinearLayout> 
</LinearLayout> 

嘗試這樣的事情,

LinearLayout(Horizontal) 
    - LinearLayout(Vertical) 
     - ImageView (for the image) 
     - Textview (for title) 
    - LinearLayout(Vertical) 
     - ImageView (for the image) 
     - Textview (for title) 
    - LinearLayout(Vertical) 
     - ImageView (for the image) 
     - Textview (for title) 
+0

是的,它實際上是安排三個相同的空間佈局,從而得到太大的圖像。但我確實想要像Iv發佈的圖片。利潤率。 –

+0

我會建議保持你的圖像視圖寬度像24dp ...,如果你有一個svg形式的圖像使用矢量繪製顯示他們 –

+0

我添加了android:layout_margin =「10dp」和layout_width =「24dp」,但現在圖像視圖高度太大。不知道爲什麼 –

2

請試試這個

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:weightSum="3"> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:layout_weight="1" 
      android:gravity="center" 
      android:orientation="vertical" 
      android:padding="5dp"> 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/brands" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="brands" /> 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:layout_weight="1" 
      android:gravity="center" 
      android:orientation="vertical" 
      android:padding="5dp"> 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/stores" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Stores" /> 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:layout_weight="1" 
      android:gravity="center" 
      android:orientation="vertical" 
      android:padding="5dp"> 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:src="@drawable/coupons" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Coupons" /> 
     </LinearLayout> 
    </LinearLayout> 


</RelativeLayout> 
+0

在這裏發佈的專業提示:讀者更喜歡真實的文字而不是縮寫「txtspk」 - 後者對於Facebook聊天很好,但我們寧願讓事情在這裏更具可讀性。我們非常希望段落文本不會與代碼格式合併,再次讓事情變得儘可能清晰。希望有所幫助! – halfer

1

改變所有內部佈局

機器人:layout_gravity = 「左」

android:layout_margin="10dp"//as required 

,改變

機器人:weightSum = 「3」

在父佈局

2
<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical"> 
<!-- Root element should wrap to parent size. --> 

<!-- Your view xml codes. --> 

<!--Bottom bar layout should be in root element. Parent should be Relative layout so that we can always align to parent bottom--> 
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:weightSum="3"> 

    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:gravity="center" 
     android:orientation="vertical"> 


     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/brands" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="brands" /> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:gravity="center" 
     android:orientation="vertical"> 

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/stores" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="brands" /> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:gravity="center" 
     android:orientation="vertical"> 

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/coupons" /> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="brands" /> 

    </LinearLayout> 
</LinearLayout> 

嘗試此。我認爲它會解決你的問題。

+0

謝謝是的。除了我添加了 android:layout_width =「63dp」 android:layout_height =「85dp」 –