Deskclick 闹钟界面实现

Deskclick 闹钟界面实现

 

对于deskclock闹钟的界面的绘制:

activity

public class MainActivity extends Activityimplements OnItemClickListener

实现内部类:

class MyAdapter extends BaseAdapter

并重写getCount,getItem,getItemId,getView这四个方法。

由于上一篇提到listview的绘制原理,所以getview会被重复调用多次。

在getView函数中:

//获取当前view 这个item里面的id:indicator

//对该 indicator 设置监听,目的是实现对item实现分别处理的效果,配合//DontPressWithParentLayout 类完成任务

                     View indicator =view.findViewById(R.id.indicator);

                     indicator.setOnClickListener(newOnClickListener() {

                            @Override

                            public void onClick(Viewv) {

                                   // TODOAuto-generated method stub

                            }

                     });

DontPressWithParentLayout

public class DontPressWithParentLayoutextends LinearLayout {

 

   public DontPressWithParentLayout(Context context, AttributeSet attrs) {

       super(context, attrs);

    }

//满足下面条件的会被截断,从而不会将单击事件发送给整个item

// DontPressWithParentLayout的具体利用参看xml文档

   @Override

   public void setPressed(booleanpressed) {

       // If the parent is pressed, do not set to pressed.

       if (pressed && ((View) getParent()).isPressed()) {

           return;

       }

       super.setPressed(pressed);

    }

}

 

Alarm_time.xml:

<LinearLayout

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

   android:layout_width="match_parent"

   android:layout_height="wrap_content"

   android:orientation="horizontal">

   

   <com.example.deskclock_ui.DontPressWithParentLayout

       android:id="@+id/indicator"

       android:layout_width="68dip"

       android:layout_height="68dip"

       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.example.deskclock_ui.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" />

 

    <com.example.deskclock_ui.DontPressWithParentLayout

       android:id="@+id/digitalClock"

       android:background="@drawable/clock_selector"

       android:gravity="center"

       android:layout_width="match_parent"

       android:layout_height="match_parent"

       android:orientation="horizontal">

 

       <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:attr/textColorPrimary"/>

   </com.example.deskclock_ui.DontPressWithParentLayout>

 

</LinearLayout>

 

效果图:

 

 

 


下载地址:

http://download.csdn.net/download/wangwei890702/5652699

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值