【问题标题】:How to click through a TextView inside a TableRow如何单击 TableRow 中的 TextView
【发布时间】:2013-12-04 12:32:14
【问题描述】:

我的第一个问题在这里! 我需要一些帮助来点击我的 TextViews。 它们被插入到动态添加到 TableLayout 的 TableRow 中。它们几乎占据了 TableRows 的所有空间(减去填充),因此我无法做到这一点,因此 TableRows ClickListener 注册了点击而不是 TextViews。只有当我单击行的边缘(同样是填充)时,它才会起作用。

这是要插入到预定义 TableLayout 中的行的 XML,其中包含我需要单击的文本视图。

<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/cell_shape"
android:padding="5dp"
android:clickable="true"
 >

<TextView
    android:id="@+id/contactId"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:visibility="gone"

    android:clickable="false"
    android:longClickable="false"
    android:linksClickable="false"
    android:focusable="false"
    android:focusableInTouchMode="false" />

<TextView
    android:id="@+id/contactEntryLastName"
    android:layout_width="0dip"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:textColor="@color/black"
    android:textIsSelectable="true"
    android:background="@android:color/transparent"

    android:clickable="false"
    android:longClickable="false"
    android:linksClickable="false"
    android:focusable="false"
    android:focusableInTouchMode="false" />

<TextView
    android:id="@+id/contactEntryFirstName"
    android:layout_width="0dip"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:textColor="@color/black"
    android:textIsSelectable="true"
    android:background="@android:color/transparent" 

    android:clickable="false"
    android:longClickable="false"
    android:linksClickable="false"
    android:focusable="false"
    android:focusableInTouchMode="false" />

</TableRow>

我一直在寻找解决方案,我发现的唯一解决方案是将所有“可点击”和可聚焦属性设置为 false,但这些都不起作用。

确实应该有一个简单的解决方案,对吧!?

【问题讨论】:

    标签: java android click-through


    【解决方案1】:

    试试这个

    <?xml version="1.0" encoding="utf-8"?>
    <TableRow xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/cell_shape"
    android:padding="5dp"
    android:descendantFocusability="blocksDescendants" >
    
    <TextView
        android:id="@+id/contactId"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:visibility="gone"
    
        android:clickable="false"
        android:longClickable="false"
        android:linksClickable="false"
        android:focusable="false"
        android:focusableInTouchMode="false" />
    
    <TextView
        android:id="@+id/contactEntryLastName"
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:textColor="@color/black"
        android:textIsSelectable="true"
        android:background="@android:color/transparent"
    
        android:clickable="false"
        android:longClickable="false"
        android:linksClickable="false"
        android:focusable="false"
        android:focusableInTouchMode="false" />
    
    <TextView
        android:id="@+id/contactEntryFirstName"
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:textColor="@color/black"
        android:textIsSelectable="true"
        android:background="@android:color/transparent" 
    
        android:clickable="false"
        android:longClickable="false"
        android:linksClickable="false"
        android:focusable="false"
        android:focusableInTouchMode="false" />
    
    </TableRow>
    

    【讨论】:

    • 不,这没有帮助 :( 我也尝试了“beforeDescendants”和“afterDescendants”,但都没有成功。这样的事情会如此复杂,真是太奇怪了。
    猜你喜欢
    • 2012-07-05
    • 1970-01-01
    • 1970-01-01
    • 2011-09-16
    • 2012-02-02
    • 1970-01-01
    • 1970-01-01
    • 2011-10-05
    • 2015-08-08
    相关资源
    最近更新 更多