2017-05-26 16 views
5

muszę coś jak RatingBar do wyboru szereg miesięcy w roku,Wybór widoków niczym ratingbar

gdzie użytkownik może wybrać marsz i przesuwa palcem w kierunku kierunku i jest on wybrany. Nie mogę mieć czegoś "nie wybranego" w środku.

Aby zilustrować,
Months selected

W takim przypadku, użytkownik wybiera 'Jan' i 'Abr'. Nie znalazłem nic konkretnego dla tego przypadku, więc zastanawiałem się, czy ktoś go znalazł, czy powinienem to zrobić ręcznie.

Dzięki! :)

+0

nie wiem dlaczego mam downvoted, może mi pan wyjaśnić, dlaczego? –

+0

Czy możesz podzielić się tym, czego próbowałeś, abyśmy mogli zasugerować ulepszenia? –

+0

Niestety, nie byłem w stanie oddalić się znacznie od tego problemu, ponieważ nie mam pomysłu na ten problem. –

Odpowiedz

4

Cóż, skończyłem robiąc prawie ręcznie cały kod. Opublikuję tutaj, więc jeśli ktoś potrzebuje tego samego, będzie tutaj.
Przede wszystkim mam FlexboxLayout utrzymywany przez Google, który opakowuje widoki do następnej linii. Następnie dodałem do środka wszystkie 13 pól wyboru i ustaw tło i textColor na podstawie StateLists.
kodu widoku:

<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> 

wewnątrz Res/kolor/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> 

wewnątrz Res/rozciągliwej/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> 

wewnątrz Res/odkształcalne/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> 

i wewnątrz RES/rozciągliwej/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> 
1

tutaj są dwie biblioteki materiał-range-bar:

dependencies { 
    compile 'com.appyvet:materialrangebar:1.3' 
} 

i Zakres poszukiwania bar:

dependencies { 
     compile 'com.yahoo.mobile.client.android.util.rangeseekbar:rangeseekbar-library:0.1.0' 

}

Możecie lubią mieć spójrz na łącza this i this. Być może nie jest to dokładnie to, czego szukasz, ale przy odrobinie personalizacji, myślę, że to pomoże. Jednak nie próbowałem ich jeszcze. Po prostu googlowałem dla ciebie.