开发者

Odd visual issue with ListView item layout with two pressable pieces

开发者 https://www.devze.com 2023-02-04 03:19 出处:网络
I wanted to make a ListView where the items have two pressable pieces, like the layouts that show up in a couple of places in the stock Android phone/contacts application:

I wanted to make a ListView where the items have two pressable pieces, like the layouts that show up in a couple of places in the stock Android phone/contacts application:

Odd visual issue with ListView item layout with two pressable pieces

Odd visual issue with ListView item layout with two pressable pieces

I have the layout working fine, including handling events from each piece separately, except for a visual issue when the smaller piece is pressed. In my application the smaller piece only gets a small ellipse for the background when it is pressed, like this:

Odd visual issue with ListView item layout with two pressable pieces

Note that is actually not my application - that is NubDial, but my application has the same problem. Since NubDial uses the exact same XML layout as the phone app, I'm not sure how relevant the list item layouts are, but here they are anyway:

Contacts list: contacts_list_item.xml

NubDial: contacts_list_item.xml

Does anybody know w开发者_JAVA百科hat might be happening there?


Hmm. I don't have a way to test this right now, but I think I have an idea what you would need to do. Looking through the source, for the call button, Google uses a custom View called DontPressWithParentImageView. It basically doesn't set the pressed state if you're pressing the parent (keeping the phone icon from looking pressed if you're actually pressing the contact item).

I can't find the actual adapter source right now, but what you should look at doing is, within your ListAdapter, in the getView() method, give your call button (your DontPressWithParentImageView, in this case) an onClickListener() that calls up the dialer with the selected contact's number. Meanwhile, your onListItemClick() method for your ListView can handle the alternate action (i.e. bringing up contact details).


You can do one thing. In your list view row layout, you can divide the sections as 'main container' which contains 'left container' and 'right container' viewgroup.

And set 'clickable=true' to both left and right container, and then you can identify the clicks by its 'id'.


The layout was using this background drawable for the button on the right:

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_window_focused="false"
        android:drawable="@android:color/transparent" />
    <item android:state_focused="false" android:state_pressed="true"
        android:drawable="@*android:drawable/list_selector_background_transition" />
    <item android:state_focused="false" android:state_pressed="false"
        android:drawable="@android:drawable/screen_background_dark"/>

</selector>

Copying the list_selector_background_transition drawable and its images into my project fixed the issue. I thought this was pretty odd, and I would have liked to use the system drawable if possible. Anyone know what was going on?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号