設計日曆視圖
回答
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