简体   繁体   English

在Android的TableView单元格中使用透明按钮

[英]Use a transparent button in TableView cells on Android

Please take a look at the following layout. 请查看以下布局。 This layout is used in a TableView and is applied in each row. 此布局在TableView中使用,并应用于每一行。 The question is why the button in each tablerow is only clickable in the upper half of the tableviewcell when transparency is applied. 问题是,为什么在应用透明度时,每个表行中的按钮仅在tableviewcell的上半部分才可单击。 Without transparency the button fills up the correct amount of space. 没有透明度,按钮将填满正确的空间。

<?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" />

Any help is greatly appreciated! 任何帮助是极大的赞赏! Regards, Raoul 问候,拉乌尔

Turns out that the Button needs a minimum height. 事实证明,按钮需要最小高度。 So the altered XML definition could be: 因此,更改后的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" />

This worked for me! 这对我有用!

Regards, Raoul. 问候,拉乌尔。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM