ListView之Item click事件与Item中的控件点击事件共存

本文介绍了一个具体的Android应用布局案例,通过使用RelativeLayout实现商品列表项的布局,并详细展示了各个控件的属性设置,如CheckBox、ImageView等,重点在于如何合理设置布局参数以达到良好的显示效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<pre name="code" class="html"><pre name="code" class="html"> 1、android:descendantFocusability="blocksDescendants"
2、 android:focusable="false"
 



<?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="100dp"
    android:background="@color/whiteColor"
    android:descendantFocusability="blocksDescendants"
    android:paddingBottom="@dimen/dimen6"
    android:paddingTop="@dimen/dimen6" >

    <CheckBox
        android:id="@+id/cart_check"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_marginLeft="@dimen/dimen6"
        android:paddingRight="@dimen/dimen6"
        android:focusable="false"
        android:button="@drawable/button_selector"
        android:gravity="center" />

    <ImageView
        android:id="@+id/cart_image"
        android:layout_width="100dp"
        android:layout_height="70dp"
        android:layout_centerVertical="true"
        android:layout_toRightOf="@id/cart_check"
        android:scaleType="fitXY"
        android:src="@drawable/ic_launcher" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_toRightOf="@id/cart_image" >

        <RelativeLayout
            android:id="@+id/rl_cartlist_item_info"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/whiteColor"
            android:visibility="visible" >

            <com.lecake.android.ui.MyCustomTextView
                android:id="@+id/cart_edit"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:layout_marginRight="5dp"
                android:background="@drawable/gray_bt_stroke_shape"
                android:gravity="center"
                android:paddingBottom="@dimen/dimen4"
                android:paddingLeft="@dimen/dimen6"
                android:paddingRight="@dimen/dimen6"
                android:paddingTop="@dimen/dimen4"
                android:text="编辑"
                android:textSize="14sp" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:layout_toLeftOf="@id/cart_edit"
                android:orientation="vertical" >

                <com.lecake.android.ui.MyCustomTextView
                    android:id="@+id/cart_name"
                    android:layout_width="wrap_content"
                    android:layout_height="0dp"
                    android:layout_weight="1"
                    android:paddingTop="2dp"
                    android:singleLine="true"
                    android:text="雪域牛栏芝士蛋糕" />

                <com.lecake.android.ui.MyCustomTextView
                    android:id="@+id/cart_englishname"
                    android:layout_width="wrap_content"
                    android:layout_height="0dp"
                    android:layout_weight="1"
                    android:ellipsize="end"
                    android:maxEms="10"
                    android:singleLine="true"
                    android:text="Le Cheesecake" />

                <com.lecake.android.ui.MyCustomTextView
                    android:id="@+id/cart_spec"
                    android:layout_width="wrap_content"
                    android:layout_height="0dp"
                    android:layout_weight="1"
                    android:text="1磅    34*23cm" />

                <LinearLayout
                    style="@style/BaseLineHeight"
                    android:layout_width="wrap_content"
                    android:layout_height="0dp"
                    android:layout_weight="1"
                    android:orientation="horizontal" >

                    <com.lecake.android.ui.MyCustomTextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:singleLine="true"
                        android:text="¥"
                        android:textColor="@color/gray_light" />

                    <com.lecake.android.ui.MyCustomTextView
                        android:id="@+id/cart_price"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:singleLine="true"
                        android:text="12  x1"
                        android:textColor="@color/red" />
                </LinearLayout>
            </LinearLayout>
        </RelativeLayout>

        <LinearLayout
            android:id="@+id/ll_cartlist_item_edit"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_centerVertical="true"
            android:layout_marginLeft="10dp"
            android:background="@color/whiteColor"
            android:orientation="vertical"
            android:visibility="gone" >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="30dp"
                android:gravity="center_vertical"
                android:orientation="horizontal" >

                <ImageView
                    android:id="@+id/decEt"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_marginRight="@dimen/dimen6"
                    android:src="@drawable/dec_press" />

                <EditText
                    android:id="@+id/numEt"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:background="@drawable/cart_input_bg"
                    android:ems="10"
                    android:enabled="false"
                    android:gravity="center"
                    android:text="1" >
                </EditText>

                <ImageView
                    android:id="@+id/addImg"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:layout_marginLeft="@dimen/dimen6"
                    android:layout_marginRight="@dimen/dimen20"
                    android:src="@drawable/inc_press" />

                <com.lecake.android.ui.MyCustomTextView
                    android:id="@+id/tv_cartlist_item_save"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="5dp"
                    android:background="@drawable/gray_bt_stroke_shape"
                    android:gravity="center"
                    android:paddingBottom="@dimen/dimen4"
                    android:paddingLeft="@dimen/dimen6"
                    android:paddingRight="@dimen/dimen6"
                    android:paddingTop="@dimen/dimen4"
                    android:text="完成"
                    android:textSize="14sp" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="30dp"
                android:layout_marginTop="@dimen/dimen6"
                android:gravity="center_vertical"
                android:orientation="horizontal" >

                <GridView
                    android:id="@+id/gridview"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="@dimen/dimen20"
                    android:layout_weight="1"
                    android:background="#FFFFFF"
                    android:cacheColorHint="#00000000"
                    android:gravity="left"
                    android:listSelector="#00000000"
                    android:numColumns="4"
                    android:scrollbars="none" />

                <com.lecake.android.ui.MyCustomTextView
                    android:id="@+id/tv_cartlist_item_del"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="5dp"
                    android:background="@drawable/gray_bt_stroke_shape"
                    android:gravity="center"
                    android:paddingBottom="@dimen/dimen4"
                    android:paddingLeft="@dimen/dimen6"
                    android:paddingRight="@dimen/dimen6"
                    android:paddingTop="@dimen/dimen4"
                    android:text="删除"
                    android:textSize="14sp" />
            </LinearLayout>
        </LinearLayout>
    </RelativeLayout>

</RelativeLayout>



                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值