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