Hi,

I am trying to achieve listview row layout that would let me use "click
areas" (views i could bind OnClickListener to) no matter on real row
content. I do not want to use OnTouchListener, so my attempt is based on
using RelativeLayout and overlay real row content with "click areas". But
for some odd reasons I am unable to make it work, desipie recent beta of
ADT shows the layout as expected. When deployed on device it does not work.

Any notes, ideas or hints highly appreciated.

I asked that question on StackOveflow:
http://stackoverflow.com/questions/13108968/listview-row-content-independent-clickable-areasso
here's copy of that question:


------------------------------


I got listview's row layout like this (this is stripped down version of my
real layout so do not comment of things like single elements wrapped in
LinearLayout etc. - it just to illustrate the issue - final version got
more elements there):

[image: Inline images 1]


XML file is below for reference, but I shortly describe what I want to
achieve:

   - blue box (icon) and "usually long text here" TextView are row "real"
   content (item_main_container). It can be anything - it shall be
   irrelevant. This layer content is not clickable.
   - the red and green boxes are views I bind row's OnCliclListeners to
   (wrapped in item_click_area_container)- I just want user to be able to
   tap on the row, no matter what's item_main_container's content really is
   (so these red/green are transparent in the app). These are set transparent
   on the image so you can see item_main_content thru it). Please note red
   and green represent *separate* actions. I need to be able to have more
   elements on that layers (i.e. 4 or 5) to handle separate actions depending
   on where user tapped.
   - the yellow area (button_bar_container) holds buttons user may want to
   tap.

So basically item_click_area_container overlays item_main_container, but
not button_bar_container, which is above
item_click_area_containerotherwise user would not be able to tap on
any of its button.

Layout outline looks like this:

[image: Inline images 2]


*QUESTIONS*

   1. Why this is not working as expected and/or how to fix that?
   2. Is there any better way of having content independent click areas
   than using approach like mine item_click_area_container without using
   OnTouchListener?


------------------------------

*Layout XML*

<?xml version="1.0" encoding="utf-8"?><LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android";
    android:id="@+id/item_container"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">

    <RelativeLayout
        android:layout_width="fill_parent"
          android:layout_height="wrap_content">

        <LinearLayout
            android:id="@+id/item_main_container"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content">

            <ImageView
               android:id="@+id/item_avatar"
               android:layout_width="40dp"
               android:layout_height="40dp"
               android:background="#0000ff"
               android:src="@drawable/icon_help"/>

            <LinearLayout
               android:layout_width="fill_parent"
               android:layout_height="wrap_content"
               android:orientation="vertical">

               <TextView android:id="@+id/item_body"
                 android:layout_width="fill_parent"
                 android:layout_height="fill_parent"
                 android:text="Usually long text here..."
                 android:textColor="#ffffff"/>
            </LinearLayout>

        </LinearLayout>

        <LinearLayout
               android:id="@+id/item_click_area_container"
               android:layout_width="fill_parent"
               android:layout_height="100dp">
            <LinearLayout
               android:id="@+id/green_click"
               android:layout_width="fill_parent"
               android:layout_height="fill_parent"
               android:layout_weight="1"
               android:background="#7700ff00">
            </LinearLayout>
            <LinearLayout
               android:id="@+id/red_click"
               android:layout_width="fill_parent"
               android:layout_height="fill_parent"
               android:layout_weight="2"
               android:background="#77ff0000">
            </LinearLayout>
        </LinearLayout>

    </RelativeLayout>

    <LinearLayout
       android:id="@+id/button_bar_container"
       android:layout_width="fill_parent"
       android:layout_height="50dp"
       android:layout_marginTop="3dp"
       android:background="#ffff00">
    </LinearLayout>
</LinearLayout>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to