一种继承自linearlayout的布局可以。。

一种继承自linearlayout的布局可以。在listview中包含checkbox,这时候闹钟的处理时,activity实现一个OnItemClickListener的监听,点击每一项的监听。然后在checkbox单独拿出去写一个类,继承LinearLayout,重写setPressed()这个方法,以实现“当点击checkbox的时候不触发parent的click事件”

/*
 * Copyright (C) 2009 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.cn.daming.deskclock;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;

/**
 * Special class to to allow the parent to be pressed without being pressed
 * itself. This way the time in the alarm list can be pressed without changing
 * the background of the indicator.
 */
public class DontPressWithParentLayout extends LinearLayout {

    public DontPressWithParentLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public void setPressed(boolean pressed) {
        // If the parent is pressed, do not set to pressed.
        if (pressed && ((View) getParent()).isPressed()) {
            return;
        }
        super.setPressed(pressed);
    }
}
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2008 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at
  
          http://www.apache.org/licenses/LICENSE-2.0
  
     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
     android:padding="8dp"
    android:background="@android:color/white">

    <!-- I can't use a normal checkbox here for a couple reasons:
         1. The checkbox button resources cannot contain layouts so I have to
            use 2 views for the clock and the bar.
         2. The normal checkbox has a really messed up layout. Using the button
            attribute produces a left-aligned image that has some kind of
            minimum height. If the bar is a checkbox, it is too tall and is
            clipped on the right.
    -->
    <com.cn.daming.deskclock.DontPressWithParentLayout android:id="@+id/indicator"
        style="@style/alarm_list_left_column"
        android:background="@drawable/clock_selector"
        android:gravity="center"
        android:orientation="vertical">
        <CheckBox android:id="@+id/clock_onoff"
            android:focusable="false"
            android:clickable="false"
            android:background="@drawable/indicator_clock_onoff"
            android:duplicateParentState="true"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_gravity="center"
            android:button="@null" />
        <ImageView android:id="@+id/bar_onoff"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:paddingTop="4dip"
            android:src="@drawable/ic_indicator_off" />
    </com.cn.daming.deskclock.DontPressWithParentLayout>

        <!-- note by wangxianming  android:background="?android:attr/windowBackground" -->
    <ImageView
        android:src="@drawable/divider_vertical_dark"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:paddingTop="4dip"
        android:paddingBottom="4dip"
        android:scaleType="fitXY"
        android:gravity="fill_vertical" />
     
    <!-- A layout that displays the time.  Shows time, am/pm (if 12-hour),
         and an optional line below, used for day/days of week -->
    <com.cn.daming.deskclock.DigitalClock android:id="@+id/digitalClock"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:gravity="center_vertical"
        android:layout_weight="1"
        android:orientation="vertical"
        android:paddingLeft="16dip"
        android:paddingRight="16dip">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:baselineAligned="true">

            <TextView android:id="@+id/timeDisplay"
                android:includeFontPadding="false"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingRight="6dip"
                android:textSize="28sp"
               android:textColor="@android:color/black"/>

            <TextView android:id="@+id/am_pm"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:textStyle="bold"
                android:textColor="@android:color/black"/>

            <TextView android:id="@+id/label"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:paddingLeft="8dip"
                android:textAppearance="?android:attr/textAppearanceSmall"
                android:textColor="@android:color/black"
                android:textStyle="bold"
                android:gravity="right"
                android:singleLine="true"/><!--  android:textColor="?android:attr/textColorTertiary" -->

        </LinearLayout>

        <TextView android:id="@+id/daysOfWeek"
            android:includeFontPadding="false"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceSmall"
           android:textColor="@android:color/black"/>

    </com.cn.daming.deskclock.DigitalClock>

</LinearLayout>

 

转载于:https://www.cnblogs.com/ct732003684/archive/2013/02/05/2892583.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值