我想在下图中创建一个类似日历的视图,但我不知道从哪里开始。我想找到最好的方法。我想到了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. 日历设计
- 2. 设计日历系统,如Google日历
- 3. DHTMLX计划程序 - 日历视图 - 将焦点设置为config.mark_now
- 4. 设计自己的日历视图....从哪里开始?
- 5. 如何在Twitter Bootstrap中设计全屏日历视图?
- 6. jQuery全日历默认视图设置
- 7. Android日历视图
- 8. Android日历视图?
- 9. 日历视图android
- 10. iPhone日历视图?
- 11. 年视图日历
- 12. 每日日历视图
- 13. iPhone日历日视图
- 14. PHP日历日视图
- 15. 日历日视图逻辑
- 16. 谷歌日历日视图
- 17. Android:日历的UI设计
- 18. ASP.NET MVC日历设计
- 19. PHP日历设计问题
- 20. 日历视图的Android 2
- 21. d3.js日历视图周
- 22. 日历选取器视图
- 23. Jenkins的日历视图
- 24. Windows Phone日历 - 月视图
- 25. 日历列表视图Android
- 26. GridView的日历视图
- 27. 日历周视图Android
- 28. SwiftDate的日历视图
- 29. 关于android日历视图
- 30. CouchDB的“度日型”视图设计
我更新了我的答案,提供了一个可以让您的日历工作的概念。 – AedonEtLIRA 2012-04-25 15:06:45