我需要这样的东西在一年中选择一个月份范围的的RatingBar,选择的观点类似的RatingBar
,用户可以选择行军,并朝着一个方向移动手指,它被选中。我在中间不能有“未选中”的东西。
在这种情况下,用户选择了 '月' 和 'ABR'。 我没有找到任何具体的这种情况,所以,我想知道是否有人遇到这种情况,或者我应该手动做这件事。
谢谢! :)
我需要这样的东西在一年中选择一个月份范围的的RatingBar,选择的观点类似的RatingBar
,用户可以选择行军,并朝着一个方向移动手指,它被选中。我在中间不能有“未选中”的东西。
在这种情况下,用户选择了 '月' 和 'ABR'。 我没有找到任何具体的这种情况,所以,我想知道是否有人遇到这种情况,或者我应该手动做这件事。
谢谢! :)
那么,我最终几乎手动完成所有的代码。我会在这里发布,如果有人需要相同的东西,它会在这里。
首先,我有一个由Google维护的FlexboxLayout,它将视图包装到下一行。然后,我在里面添加了13个复选框,并根据StateLists设置背景和textColor。
视图代码:
<com.google.android.flexbox.FlexboxLayout
android:id="@+id/fl_cadastrofonterendamensalactivity_months_container"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:alignContent="stretch"
app:justifyContent="space_around"
app:alignItems="center"
app:flexWrap="wrap">
<CheckBox
android:id="@+id/cb_monthlist_jan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/months_statelist"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:button="@null"
android:gravity="center"
android:text="@string/cadastro_fonterendamensal_mes_jan"
android:textColor="@color/months_textcolor"
android:textStyle="bold"
/>
<CheckBox
android:id="@+id/cb_monthlist_fev"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/months_statelist"
android:button="@null"
android:gravity="center"
android:text="@string/cadastro_fonterendamensal_mes_fev"
android:textColor="@color/months_textcolor"
android:textStyle="bold"/>
<CheckBox
android:id="@+id/cb_cadastromonthlist_mar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/months_statelist"
android:button="@null"
android:gravity="center"
android:text="@string/cadastro_fonterendamensal_mes_mar"
android:textColor="@color/months_textcolor"
android:textStyle="bold"/>
<CheckBox
android:id="@+id/cb_cadastromonthlist_abr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/months_statelist"
android:button="@null"
android:gravity="center"
android:text="@string/cadastro_fonterendamensal_mes_abr"
android:textColor="@color/months_textcolor"
android:textStyle="bold"/>
<CheckBox
android:id="@+id/cb_cadastromonthlist_mai"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/months_statelist"
android:button="@null"
android:gravity="center"
android:text="@string/cadastro_fonterendamensal_mes_mai"
android:textColor="@color/months_textcolor"
android:textStyle="bold"/>
<CheckBox
android:id="@+id/cb_cadastromonthlist_jun"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/months_statelist"
android:button="@null"
android:gravity="center"
android:text="@string/cadastro_fonterendamensal_mes_jun"
android:textColor="@color/months_textcolor"
android:textStyle="bold"/>
<CheckBox
android:id="@+id/cb_cadastromonthlist_jul"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/months_statelist"
android:button="@null"
android:gravity="center"
android:text="@string/cadastro_fonterendamensal_mes_jul"
android:textColor="@color/months_textcolor"
android:textStyle="bold"/>
<CheckBox
android:id="@+id/cb_cadastromonthlist_ago"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/months_statelist"
android:button="@null"
android:gravity="center"
app:layout_wrapBefore="true"
android:text="@string/cadastro_fonterendamensal_mes_ago"
android:textColor="@color/months_textcolor"
android:textStyle="bold"/>
<CheckBox
android:id="@+id/cb_cadastromonthlist_set"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/months_statelist"
android:button="@null"
android:gravity="center"
android:text="@string/cadastro_fonterendamensal_mes_set"
android:textColor="@color/months_textcolor"
android:textStyle="bold"/>
<CheckBox
android:id="@+id/cb_cadastromonthlist_out"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/months_statelist"
android:button="@null"
android:gravity="center"
android:text="@string/cadastro_fonterendamensal_mes_out"
android:textColor="@color/months_textcolor"
android:textStyle="bold"/>
<CheckBox
android:id="@+id/cb_cadastromonthlist_nov"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/months_statelist"
android:button="@null"
android:gravity="center"
android:text="@string/cadastro_fonterendamensal_mes_nov"
android:textColor="@color/months_textcolor"
android:textStyle="bold"/>
<CheckBox
android:id="@+id/cb_cadastromonthlist_dez"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/months_statelist"
android:button="@null"
android:gravity="center"
android:text="@string/cadastro_fonterendamensal_mes_dez"
android:textColor="@color/months_textcolor"
android:textStyle="bold"/>
<CheckBox
android:id="@+id/cb_cadastromonthlist_dct"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/months_statelist"
android:button="@null"
android:gravity="center"
android:text="@string/cadastro_fonterendamensal_mes_dct"
android:textColor="@color/months_textcolor"
android:textStyle="bold"/>
</com.google.android.flexbox.FlexboxLayout>
内部RES /颜色/ months.textcolor.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/color_background" android:state_checked="true"/>
<item android:color="@android:color/white" android:state_checked="false"/>
</selector>
内部RES /抽拉/ months_statelist.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@drawable/checkbox_checked"
android:state_checked="true"/>
<item
android:drawable="@drawable/checkbox_unchecked"
android:state_checked="false"/>
</selector>
内部RES /抽拉/ checkbox_checked.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF"/>
<corners android:radius="100dp"/>
<size
android:width="-2dp"
android:height="-2dp"/>
<padding
android:bottom="4dp"
android:left="4dp"
android:right="4dp"
android:top="4dp"/>
</shape>
和内部RES /绘制/ checkbox_unchecked.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@android:color/transparent"/>
<stroke
android:width="1dp"
android:color="#FFFFFF"/>
<corners android:radius="100dp"/>
<size
android:width="40dp"
android:height="40dp"/>
<padding
android:bottom="4dp"
android:left="4dp"
android:right="4dp"
android:top="4dp"/>
</shape>
我不知道为什么我得到downvoted,也许你能解释我为什么? –
可以请你分享一下你曾尝试过的一样吗,以便我们可以提出改进建议 –
可悲的是我一直无法从这个问题进一步解答,因为我对这个问题没有任何想法 –