English 中文(简体)
日历的设计 观点
原标题:Designing a Calendar View

我希望在以下形象中形成像日历一样的观点,但我不知道何时开始。 我想就此找到最佳办法。 我对GredView进行了思考,但没有做任何工作。 是否有任何建议?

“entergraph

最佳回答

Android没有在SDK中提出任何日历观点。 从开发商的角度来看,这是一个巨大的损失。 有许多情况有利于显示一个月的天数,并为用户选择这一天提供某种选择。

一种解决办法是使用第三当事方部分。 第二是由你自己执行。

检查这些联系会有助于你

页: 1

http://caultinthemobileweb.wordpress.com/106/20/how-to-implement-calendarview-in-android/

问题回答

使用一个网路布主的电网布。 你可以利用GridLayout执行点击指挥,并利用一些精炼者的工作,你可以管理周/月的天数。

Edit:

这里是一个粗略的概念,即你可以做些什么,GredView将如何为你工作。

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);
            }
    }
}

你们可以把横向线索带入垂直线Layout,所有文本概览都加权。

 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>




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签