2013-05-27 65 views
0

enter image description here低於線性佈局

刪除按鈕的額外空間有下面的按鈕這個額外的空間,我不知道爲什麼會在那裏。我嘗試了一切,尋找有這種問題的人,可惜我什麼也沒找到。這是要麼刪除額外的空間和/或降低完美對齊。

這裏是我的xml文件

<RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 
     <LinearLayout 
      android:id="@+id/button_layout" 
      android:layout_alignParentTop="true" 
      android:orientation="horizontal" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:background="#262626" 
      android:gravity="center"> 
      <Button 
       android:id="@+id/receipts_button" 
       android:background="@android:color/transparent" 
       android:drawableTop="@drawable/preview_save_icon" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="1"/> 
      <Button android:id="@+id/capture_button" 
       android:background="@android:color/transparent" 
       android:drawableTop="@drawable/preview_upload_icon" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="1"/> 
      <Button android:id="@+id/settings_button" 
       android:background="@android:color/transparent" 
       android:drawableTop="@drawable/preview_discard_icon" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="1"/> 
     </LinearLayout> 

回答

1

是否有您使用的按鈕,而不是ImageView的任何原因?您正在使用android:drawableTop,它會將圖像放置在頂部,並在文字底部留出一些空間! 由於您不想使用文字,因此我更容易用ImageView替換它,並將圖片設置爲來源。因此,這將在視圖中居中:

<LinearLayout 
      android:id="@+id/button_layout" 
      android:layout_alignParentTop="true" 
      android:orientation="horizontal" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:background="#262626" 
      android:gravity="center"> 
      <ImageView 
       android:id="@+id/receipts_button" 
       android:background="@android:color/transparent"     
       android:src="@drawable/ic_launcher" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="1"/> 
      <ImageView android:id="@+id/capture_button" 
       android:background="@android:color/transparent" 
       android:src="@drawable/ic_launcher"     
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="1"/> 
      <ImageView android:id="@+id/settings_button" 
       android:background="@android:color/transparent" 
       android:src="@drawable/ic_launcher" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_weight="1"/> 
     </LinearLayout> 
+0

謝謝。這幫助我很多:) – kev

+0

只是以防萬一你還沒有嘗試它下面的RKN答案也會集中圖標,但它也會拉伸它們來填充整個空間。你可以根據你想要的行爲來玩弄背景和src。 – caiocpricci2

0

試試這個, 其實當你設置的android:比重=「中心」,其屬於佈局本身,當你說layout_gravity那麼這將適用於佈局的孩子。

android:layout_gravity="center_vertical" 
0

首先,擁有許多嵌套佈局並不是一個好習慣。在你的情況下,你可以刪除LinearLayout或RelativeLayout。除此之外,雖然這將是有益的張貼整個XML, 我建議在LinearLayout中取出android:layout_alignParentTop="true",也許將是這樣的:android:layout_gravity="bottom"

0
  • 刪除android:drawableTop屬性和 android:background屬性給Button圖像。 android:drawableTop會將您的圖像放置在頂部。
  • 設置layout_gravity屬性center_vertical爲 按鈕

    <LinearLayout 
         android:id="@+id/button_layout" 
         android:layout_alignParentTop="true" 
         android:orientation="horizontal" 
         android:layout_width="fill_parent" 
         android:layout_height="wrap_content" 
         android:background="#262626" 
         android:gravity="center"> 
         <Button 
          android:id="@+id/receipts_button" 
          android:background="@drawable/preview_save_icon" 
          android:layout_width="fill_parent" 
          android:layout_height="wrap_content" 
          android:layout_gravity="center_vertical" 
          android:layout_weight="1"/> 
         <Button android:id="@+id/capture_button" 
          android:background="@drawable/preview_upload_icon" 
          android:layout_width="fill_parent" 
          android:layout_height="wrap_content" 
          android:layout_gravity="center_vertical" 
          android:layout_weight="1"/> 
         <Button android:id="@+id/settings_button" 
          android:background="@drawable/preview_discard_icon" 
          android:layout_width="fill_parent" 
          android:layout_height="wrap_content" 
          android:layout_gravity="center_vertical" 
          android:layout_weight="1"/> 
        </LinearLayout> 
    
0

原因是正確的gameower說。 除此之外,如果你想繼續使用Buttons那麼你只需要用android:drawableLeft代替android:drawableTop,你應該得到你想要的。

希望肝。