在android中自定义日历日视图

时间:2016-02-20 12:32:35

标签: android calendar material-design android-calendar

我正在创建一个应用,我希望在其中显示自定义日历日视图,如下图custom calendar day view

我试图搜索谷歌并找到一个链接Android-Week-View 但它没有用。

2 个答案:

答案 0 :(得分:1)

如果你想做每周日历,如图所示。您可以将LinearLayout方向与7 LinearLayout水平放置,其中包含垂直方向。如果问题是如何获得当天,您可以在这里查看: How the get the current day name using particular date in android? 或者在这里 Get day of the week from GregorianCalendar 如果你想要像我们在16号那样的奇怪线条你将需要一个背景可绘制,我不知道是否可以在xml中做到这一点。但是你肯定可以在ondraw方法上绘制它,这样你就可以制作一个自定义视图。然后,如果您想将自定义视图作为背景,则必须使用RelativeLayout:

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="info.androidhive.materialtabs.fragments.OneFragment"
android:weightSum="7">
<RelativeLayout android:layout_width="0dp"
    android:layout_height="70dp"
    android:layout_weight="1">
    <View android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/holo_red_light"></View>
    <TextView
        android:id="@+id/one"
        android:layout_width="match_parent"
        android:layout_height="35dp"
        android:text="day"
        android:gravity="center"/>
    <TextView
        android:gravity="center"
        android:text="num"
        android:layout_below="@id/one"
    android:layout_width="match_parent"
    android:layout_height="35dp" />
</RelativeLayout>
</LinearLayout>

这样的东西,把相对的6倍。

enter image description here

答案 1 :(得分:0)

这可以在不使用任何lib的情况下完成。只需放置一个recyclerview并添加日期数组即可。我以相同的方式和相同的设计为我的项目完成了它。但这需要一些时间,因为你在这里玩日历课并根据你的要求得到日期会产生混淆。

相关问题