【发布时间】:2016-02-20 12:32:34
【问题描述】:
我正在创建一个应用程序,我想在其中显示自定义日历日视图,如下图
我已经尝试搜索谷歌并找到一个链接Android-Week-View 但这没什么用。
【问题讨论】:
标签: android calendar material-design android-calendar
我正在创建一个应用程序,我想在其中显示自定义日历日视图,如下图
我已经尝试搜索谷歌并找到一个链接Android-Week-View 但这没什么用。
【问题讨论】:
标签: android calendar material-design android-calendar
如果你想做一个如图所示的每周日历。您可以将 LinearLayout orientaion 水平放置,并将 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>
类似的东西,把Relative放6倍。
【讨论】:
这可以在不使用任何库的情况下完成。只需放置一个 recyclerview 并向其中添加日期数组即可。我以相同的方式和相同的设计为我的项目完成了它。但这需要一些时间并且会造成混乱,因为您必须在这里玩日历类并根据您的要求获取日期。
【讨论】: