2014-10-26 57 views
0

我仍然沒有真正知道它需要多少空間佈局。按鈕佔用太多空間

我有以下xml。 底部空間高度的內部LinearLayout's設置爲wrap_content,所以它應該佔用最大高度。這是52dpImageButton設置爲wrap_content,所以按鈕應該在右側垂直居中,因爲它的24dp圖像(在xhdpi中它具有32x32像素)。那麼,爲什麼是它搭在全高度喜歡這裏顯示?:

enter image description here

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_margin="2dp"> 

    <de.ph1b.audiobook.utils.SquareImageView 
     android:id="@+id/cover" 
     android:scaleType="fitXY" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@android:color/white" 
     android:layout_gravity="bottom"> 

     <TextView 
      android:id="@+id/title" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_height="52dp" 
      android:paddingLeft="16dp" 
      android:maxLines="2" 
      android:ellipsize="end" 
      android:paddingRight="16dp" 
      android:gravity="center_vertical" 
      android:textSize="16sp" /> 

     <ImageButton 
      android:id="@+id/editBook" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      style="?android:attr/borderlessButtonStyle" 
      android:layout_gravity="center_vertical" 
      android:src="@drawable/ic_more_vert_grey600_24dp" /> 

    </LinearLayout> 

</LinearLayout> 

回答

1

要麼@drawable/ic_more_vert_grey600_24dp大於你認爲或borderlessButtonStyle具有較大的背景。

請檢查大小。我已經複製了該行爲並將ImageButton設置爲wrap_content並居中。

+0

其borderlessButtonStyle。 – 2015-03-17 23:03:40

0

更改圖像按鈕的代碼

<ImageButton 
     android:id="@+id/editBook" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     style="?android:attr/borderlessButtonStyle" 
     android:scaleType="fitXY" 
     android:gravity="center_vertical" 
     android:src="@drawable/ic_more_vert_grey600_24dp" />