1

下の画像のカレンダーのようなビューを作成したいのですが、どこから始めればよいかわかりません。これに最適なアプローチを見つけたいと思います。GridView について考えましたが、うまくいきませんでした。誰か提案はありますか?

ここに画像の説明を入力

4

3 に答える 3

2

線形レイアウト ヘッダーでグリッド レイアウトを使用します。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);
            }
    }
}
于 2012-04-25T03:40:38.807 に答える
1

AndroidはSDKでカレンダービューを提供していません。これは、開発者の観点からは大きな損失です。月の日を表示し、ユーザーが日を選択するためのオプションを提供することが有益な状況はたくさんあります。

1つの解決策は、サードパーティのコンポーネントを使用することです。2つ目は、自分で実装することです

これらのリンクを確認してください、あなたに役立ちます

http://w2davids.wordpress.com/android-simple-calendar/

この

http://caughtinthemobileweb.wordpress.com/2011/06/20/how-to-implement-calendarview-in-android/

于 2012-04-25T03:58:03.283 に答える
0

水平 LinearLayout を垂直 LinearLayout に取り込み、すべてのテキストビューを同じ重みにすることができます。

 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>
于 2012-04-25T04:06:42.570 に答える