2014-11-06 74 views
0

請看看下面的佈局。此佈局用於TableView中並應用於每一行。問題是爲什麼當應用透明度時,每個表格中的按鈕只能在tableviewcell的上半部分中單擊。 沒有透明度,按鈕會填滿正確的空間量。在Android上的TableView單元格中使用透明按鈕

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="10dp" 
    android:paddingTop="10dp" > 

    <ImageButton 
     android:id="@+id/btnSelect" 
     android:layout_width="40dp" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_centerVertical="true" 
     android:background="@color/white" 
     android:contentDescription="Geselecteerde rekening" 
     android:src="@drawable/checkbox_akkoord_uit" /> 

    <ImageView 
     android:id="@+id/imgPhoto" 
     android:layout_width="40dp" 
     android:layout_height="40dp" 
     android:layout_alignBottom="@+id/btnSelect" 
     android:layout_marginLeft="4dp" 
     android:layout_centerVertical="true" 
     android:layout_toRightOf="@+id/btnSelect" 
     android:scaleType="fitCenter" 
     android:src="@drawable/icon_foto" /> 

    <ImageView 
     android:id="@+id/imgPencil" 
     android:layout_width="40dp" 
     android:layout_height="40dp" 
     android:layout_alignBottom="@+id/btnSelect" 
     android:layout_marginLeft="4dp" 
     android:layout_centerVertical="true" 
     android:layout_toRightOf="@+id/btnSelect" 
     android:src="@drawable/potlood" /> 

    <ImageView 
     android:id="@+id/ivDrag" 
     android:layout_width="20dp" 
     android:layout_height="20dp" 
     android:layout_alignParentRight="true" 
     android:layout_marginRight="@dimen/activity_horizontal_margin" 
     android:layout_centerVertical="true" 
     android:src="@drawable/settings" /> 

    <LinearLayout 
     android:id="@+id/linearLayout1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_marginLeft="8dip" 
     android:layout_toLeftOf="@+id/ivDrag" 
     android:layout_toRightOf="@+id/imgPhoto" 
     android:orientation="vertical" > 

     <TextView 
      android:id="@+id/txtDescription" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:ellipsize="end" 
      android:maxLines="1" 
      android:text="Medium Text Medium Text" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:textColor="@color/green" 
      android:textSize="@dimen/text_size_1" /> 

     <TextView 
      android:id="@+id/txtProductname" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:ellipsize="end" 
      android:maxLines="1" 
      android:text="Small Text" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:textColor="@color/green" 
      android:textSize="@dimen/text_size_2" /> 

     <TextView 
      android:id="@+id/txtAccountnumber" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:ellipsize="end" 
      android:maxLines="1" 
      android:text="Medium Text" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:textColor="@color/green" 
      android:textSize="@dimen/text_size_3" /> 
    </LinearLayout> 

<Button 
    android:id="@+id/btnModify" 
    android:background="@android:color/transparent" 
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent" 
    android:layout_toRightOf="@+id/btnSelect" 
    android:layout_toLeftOf="@+id/ivDrag" /> 

任何幫助,不勝感激! 問候,拉烏爾

回答

0

原來,按鈕需要一個最低高度。所以更改後的XML定義可能是:

<Button 
    android:id="@+id/btnModify" 
    android:background="@android:color/transparent" 
    android:minHeight="40dp" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_toRightOf="@+id/btnSelect" 
    android:layout_toLeftOf="@+id/ivDrag" /> 

這對我有效!

問候,拉烏爾。

相關問題