菜鸟教程小白 发表于 2022-12-11 17:20:04

像IOS一样的Android年历


                                            <p><p>我想在 Android 中创建 <strong>年历</strong>,例如 <strong><code>ios</code></strong>。</p>

<p>比如这张照片。
带有年月日。</p>

<p>我用 2 个 ListView 和 1 个 GridView 来做,但是,我在年份项目之间有滞后。</p>

<p>50 年。有 12 个月的文字。</p>

<hr/>

<p> <a href="/image/pfzhD.png" rel="noreferrer noopener nofollow"><img src="/image/pfzhD.png" alt="enter image description here"/></a> </p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>看这个例子..</p>

<p> <a href="https://github.com/ik024/CalendarLibrary" rel="noreferrer noopener nofollow">https://github.com/ik024/CalendarLibrary</a> </p>

<p>对于 YearView(这显示两列,请检查此代码如何设置两列而不是满足您的要求)</p>

<p> <a href="/image/kYtHh.png" rel="noreferrer noopener nofollow"><img src="/image/kYtHh.png" alt="enter image description here"/></a> </p>

<p>在您的 xml 文件中添加以下内容:</p>

<pre><code> &lt;com.github.ik024.calendar_lib.YearView
    android:id=&#34;@+id/calendar_year_view&#34;
    android:layout_width=&#34;match_parent&#34;
    android:layout_height=&#34;wrap_content&#34;
    android:layout_centerInParent=&#34;true&#34;/&gt;
</code></pre>

<p>在您的 Activity 中实现 YearViewClickListener:</p>

<pre><code>public class MonthViewDemo extends AppCompatActivity implements YearViewClickListeners{


@Override
public void dateClicked(int year, int month, int day) {
    Toast.makeText(this, &#34;year: &#34;+year+&#34;;\nmonth: &#34;+month+&#34;;\nday: &#34;+day, Toast.LENGTH_LONG).show();
    //TODO: Perform your actions based on year or month or day clicked
}


}
</code></pre>

<p>更多请引用 YearViewDemo.java 文件。</p>

<p>自定义</p>

<p>可以自定义以下属性:</p>

<pre><code>&lt;attr name=&#34;currentDayTextColorYV&#34; format=&#34;color&#34;/&gt;
&lt;attr name=&#34;monthNameTextColorYV&#34; format=&#34;color&#34;/&gt;
&lt;attr name=&#34;daysOfMonthTextColorYV&#34; format=&#34;color&#34;/&gt;
&lt;attr name=&#34;daysOfWeekTextColorYV&#34; format=&#34;color&#34;/&gt;
&lt;attr name=&#34;eventDayBackgroundColorYV&#34; format=&#34;color&#34;/&gt;
&lt;attr name=&#34;eventDayTextColorYV&#34; format=&#34;color&#34;/&gt;
&lt;attr name=&#34;calendarBackgroundColorYV&#34; format=&#34;color&#34; /&gt;
&lt;attr name=&#34;monthNameBackgroundColorYV&#34; format=&#34;color&#34; /&gt;
&lt;attr name=&#34;displayYearTextColorYV&#34; format=&#34;color&#34; /&gt;
&lt;attr name=&#34;headerBackgroundColorYV&#34; format=&#34;color&#34; /&gt;
&lt;attr name=&#34;prevButtonBackgroundResourceYV&#34; format=&#34;reference&#34; /&gt;
&lt;attr name=&#34;nextButtonBackgroundResourceYV&#34; format=&#34;reference&#34; /&gt;
</code></pre>

<p>你需要改变三列</p>

<p>转到 calendarlib/layout/yearView.xml</p>

<p>执行此操作...并根据您的响应等进行所有更改。</p>

<pre><code>    &lt;LinearLayout
            android:layout_width=&#34;match_parent&#34;
            android:layout_height=&#34;wrap_content&#34;
            android:orientation=&#34;horizontal&#34;
            android:weightSum=&#34;1&#34;&gt;

            &lt;com.github.ik024.calendar_lib.custom.MonthView
                android:id=&#34;@+id/mv_year_view_jan&#34;
                android:layout_width=&#34;0dp&#34;
                android:layout_height=&#34;wrap_content&#34;
                android:layout_weight=&#34;0.33&#34; /&gt;

            &lt;com.github.ik024.calendar_lib.custom.MonthView
                android:id=&#34;@+id/mv_year_view_feb&#34;
                android:layout_width=&#34;0dp&#34;
                android:layout_height=&#34;wrap_content&#34;
                android:layout_weight=&#34;0.33&#34; /&gt;

            &lt;com.github.ik024.calendar_lib.custom.MonthView
                android:id=&#34;@+id/mv_year_view_march&#34;
                android:layout_width=&#34;0dp&#34;
                android:layout_height=&#34;wrap_content&#34;
                android:layout_weight=&#34;0.33&#34; /&gt;
      &lt;/LinearLayout&gt;
</code></pre>

<p>或所有其他三个</p></p>
                                   
                                                <p style="font-size: 20px;">关于像IOS一样的Android年历,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/39095730/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/39095730/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: 像IOS一样的Android年历