概述
通过 月日实现匹配星座功能 先准备数据
Android 版本数据
我是用的 array 这个可以直接拷贝到项目中直接用
<pre name="code" class="java"><string name="constellation_aries">白羊座</string>
<string name="constellation_taurus">金牛座</string>
<string name="constellation_gemini">双子座</string>
<string name="constellation_cancer">巨蟹座</string>
<string name="constellation_leo">狮子座</string>
<string name="constellation_virgo">处女座</string>
<string name="constellation_libra">天秤座</string>
<string name="constellation_scorpio">天蝎座</string>
<string name="constellation_sagittarius">射手座</string>
<string name="constellation_capricorn">摩羯座</string>
<string name="constellation_aquarius">水瓶座</string>
<string name="constellation_pisces">双鱼座</string>
<string-array name="user_constellation">
<item>@string/constellation_aries</item>
<item>@string/constellation_taurus</item>
<item>@string/constellation_gemini</item>
<item>@string/constellation_cancer</item>
<item>@string/constellation_leo</item>
<item>@string/constellation_virgo</item>
<item>@string/constellation_libra</item>
<item>@string/constellation_scorpio</item>
<item>@string/constellation_sagittarius</item>
<item>@string/constellation_capricorn</item>
<item>@string/constellation_aquarius</item>
<item>@string/constellation_pisces</item>
</string-array>
String constellation = DateTimeUtil.getConstellation(getResources().getStringArray(R.array.user_constellation),month,day);
java版本数据
public static final String[] contellationArr = {"水瓶座","双鱼座","白羊座","金牛座","双子座","巨蟹座","狮子座","处女座","天秤座","天蝎座","射手座","魔羯座"};
//contellationArr 星座的数组
//month 月份
//day 日
public static String getConstellation(String [] contellationArr,int month,int day){
int point = -1;
Double date = Double.parseDouble(month + "." + day);
if (3.21 <= date && 4.19 >= date) {
point = 0;
} else if (4.20 <= date && 5.20 >= date) {
point = 1;
} else if (5.21 <= date && 6.21 >= date) {
point = 2;
} else if (6.22 <= date && 7.22 >= date) {
point = 3;
} else if (7.23 <= date && 8.22 >= date) {
point = 4;
} else if (8.23 <= date && 9.22 >= date) {
point = 5;
} else if (9.23 <= date && 10.23 >= date) {
point = 6;
} else if (10.24 <= date && 11.22 >= date) {
point = 7;
} else if (11.23 <= date && 12.21 >= date) {
point = 8;
} else if (12.22 <= date && 12.31 >= date) {
point = 9;
} else if (1.01 <= date && 1.19 >= date) {
point = 9;
} else if (1.20 <= date && 2.18 >= date) {
point = 10;
} else if (2.19 <= date && 3.20 >= date) {
point = 11;
}
if(point == -1) {
return contellationArr[2];
}
return contellationArr[point];
}
附 :星座月份对照图一张
欢迎大家加入 android开发经验交流群:454430053
最后
以上就是无情发箍为你收集整理的日期匹配星座,月日匹配星座,android 星座的全部内容,希望文章能够帮你解决日期匹配星座,月日匹配星座,android 星座所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复