我想在下图中创建一个类似日历的视图,但我不知道从哪里开始。我想找到最好的方法。我想到了GridView,但没有成功。有人有什么建议吗?设计日历视图
设计日历视图
回答
Android不提供SDK中的任何日历视图。从开发人员的角度来看,这是一个巨大的损失。在很多情况下,显示一个月中的几天并为用户选择一天提供一些选项是有益的。
一个解决方案是使用第三方组件。第二个是由你自己
检查,以实现一个这些链接,将有助于你
http://w2davids.wordpress.com/android-simple-calendar/
这
http://caughtinthemobileweb.wordpress.com/2011/06/20/how-to-implement-calendarview-in-android/
第二个示例代码是我想要的。谢谢 – Nishant 2012-04-26 03:40:18
使用网格布局具有线性布局报头。您可以使用GridLayout实现点击命令,并使用一些奇特的适配器工作,您可以管理一周/月的日子。
编辑:
这里是你可以做什么和GridView将如何为你工作一个粗略的概念。
class CalendarView extends LinearLayout {
public CalendarView (Context context) {
super(context);
setOrientation(LinearLayout.VERTICAL);
mHeader = new LinearLayout(context);
mHeader.setOrientation(LinearLayout.HORIZONTAL);
addView(mHeader);
// Add in your days, shouldn't be too bad, they are just text views.
mCalendar = new GridView(context);
mCalendar.setColumns(mHeader.getNumViews()); // You could hard code this.
mCalendar.setAdapterView(new CalendarAdapter());
addView(mCalendar);
}
// ... Other contructors
private class CalendarAdapter extends BaseAdapter {
// Override methods, this should be too bad.
@Override public view getView (int pos, View convert, ViewGroup parent) {
ListView lv = (ListView)convert;
if (convert == null)
lv = new ListView(parent.getContext());
// Here you will need to figure out some way of
// determining the date.
CalendarDate app = (CalendarDate)lv.getTag();
// Determine if this view is already set to the correct date,
// if not rest the list view
app.sort();
lv.setAdapter(new ArrayAdapter(parent.getContext(), R.layout.datelistview, app.getDates());
}
}
public static class CalendarDate {
List<Appointment> mDates = new ArrayList<Appointment>();
public void addAppointment(Appointment app) {
mDate.add(app);
}
// ... and the rest of your methods (getters and state returns)
}
public Appointment implements Compareable<Appointment> {
private Date mDate;
private String mName; // Appointment name
private String mDesc; // Appointment description
@Override public int compareTo(Appointment to) {
return mDate.compareTo(mDate);
}
}
}
感谢您的答案哥们。我正在寻找一个日历,我可以在日历的日期标记一些事件。我从Avi Kumar Manku提供的链接中获得了示例代码,这些链接为我提供了我正在寻找的解决方案。你非常支持,感谢很多。 – Nishant 2012-04-26 04:01:02
你可以把水平的LinearLayout成垂直LinearLayout与所有textview具有相同的权重。
android:layout_weight="1"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="5dp">
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="sun" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="mon" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="tue" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="wed" />
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="thu" />
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="fri" />
<TextView
android:id="@+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="sat" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="sun" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="mon" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="tue" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="wed" />
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="thu" />
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="fri" />
<TextView
android:id="@+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="sat" />
</LinearLayout>
</LinearLayout>
请参阅我对Agarwal答案的评论。 – AedonEtLIRA 2012-04-25 14:43:18
- 1. 设计日历系统,如Google日历
- 2. 如何在Twitter Bootstrap中设计全屏日历视图?
- 3. jQuery全日历默认视图设置
- 4. 年视图日历
- 5. Android日历视图?
- 6. 日历视图android
- 7. Android日历视图
- 8. 日历日视图逻辑
- 9. iPhone日历日视图
- 10. 谷歌日历日视图
- 11. ASP.NET MVC日历设计
- 12. PHP日历设计问题
- 13. 日历列表视图Android
- 14. SwiftDate的日历视图
- 15. 如何实现iphone日历日视图
- 16. iOS:日历日视图转换
- 17. 只有日和月视图的日历
- 18. 谷歌日历中的单日视图
- 19. 日历日视图的奇怪问题
- 20. 如何在日历视图中设置图像iPhone
- 21. Firebase数据库设计:日历应用
- 22. 蒙戈DB设计活动日历
- 23. 如何设计日历控件
- 24. 笔记本/日历数据库设计
- 25. Android日历视图显示使用caldroid的两个日历
- 26. Flex设计视图
- 27. 使设计视图
- 28. 将导航控制器添加到具有日历视图的自定义设计的表格视图
- 29. JQuery的完整的日历默认视图设置发出
- 30. 可以在android中手动设置datepicker的日历视图吗?
我更新了我的答案,提供了一个可以让您的日历工作的概念。 – AedonEtLIRA 2012-04-25 15:06:45