如何在RecyclerView Android中添加时隙 [英] How to add time slot in recyclerview android

查看:52
本文介绍了如何在RecyclerView Android中添加时隙的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有recyclerview a,并且将显示所有时间.我想显示插槽类型.我应该使用任何库对这样的布局进行编码吗?或者我们可以在xml本身中进行操作. 请有人建议我

I have recyclerview a and all times will be displayed. I want to display slot type. should i use any library to code layout like that? or we can do in our xml itself. please someone suggest me

activity_booking_calender.xml

activity_booking_calender.xml

   <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/white"
android:orientation="vertical">

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_margin="@dimen/margin_large"
    android:orientation="horizontal"
    android:visibility="gone">


    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:gravity="center"
        android:text="Select Date &amp; Time"

        android:textColor="@color/black_updated"

        android:textStyle="bold" />
</RelativeLayout>

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="@dimen/startdate_enddate_text_margin_top"
    android:orientation="horizontal">

    <RelativeLayout
        android:id="@+id/relative_start_date"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_gravity="start|center"
        android:gravity="start|center"
        android:orientation="vertical"
        android:layout_alignParentLeft="true">

        <TextView
            android:layout_marginLeft="20dp"
            android:id="@+id/txt_start_date"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginBottom="@dimen/startdate_enddate_text_margin_bottom"
            android:fontFamily="@font/inter_regular"
            android:gravity="center"
            android:text="START TIME"

            android:textColor="@color/text_grey"
            android:textSize="@dimen/startdate_enddate_text"
            android:textStyle="bold" />

        <LinearLayout
            android:layout_marginLeft="20dp"
            android:id="@+id/linear_start_date"
            android:clickable="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/txt_start_date"
            android:background="@drawable/btn_grey_background_no_stroke"
            android:orientation="horizontal"
            android:paddingTop="@dimen/motorcycle_date_text_top"
            android:paddingBottom="@dimen/motorcycle_date_text_bottom">

            <ImageView
                android:layout_width="@dimen/motorcycle_date_icon_width"
                android:layout_height="@dimen/motorcycle_date_icon_height"
                android:layout_gravity="center"
                android:layout_marginStart="@dimen/motorcycle_date_icon_start"
                android:src="@drawable/ic_calendar_white"
                android:layout_marginLeft="@dimen/motorcycle_date_icon_start" />

            <TextView

                android:id="@+id/txt_select_from_date"
                android:layout_width="90dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginStart="@dimen/motorcycle_date_text_start"
                android:layout_marginEnd="@dimen/motorcycle_date_text_end"
                android:fontFamily="@font/inter_regular"
                android:gravity="center"
                android:lineSpacingExtra="14.0sp"
                android:text=""
                android:textColor="#ffffffff"
                android:textSize="@dimen/motorcycle_date_text"
                android:layout_marginRight="@dimen/motorcycle_date_text_end"
                android:layout_marginLeft="@dimen/motorcycle_date_text_start" />
        </LinearLayout>
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/relative_end_date"
        android:layout_width="wrap_content"
        android:clickable="true"
        android:layout_height="wrap_content"
        android:layout_marginRight="20dp"
        android:layout_alignParentRight="true"
        android:layout_gravity="end|center"
        android:gravity="end|center"
        android:orientation="vertical">

        <TextView
            android:id="@+id/txt_end_date"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginBottom="@dimen/startdate_enddate_text_margin_bottom"
            android:fontFamily="@font/inter_regular"
            android:gravity="center"
            android:text="END TIME"
            android:textColor="@color/text_grey"
            android:textSize="@dimen/startdate_enddate_text"
            android:textStyle="bold" />

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/txt_end_date"
            android:background="@drawable/btn_grey_background_no_stroke"
            android:orientation="horizontal"
            android:paddingTop="@dimen/motorcycle_date_text_top"
            android:paddingBottom="@dimen/motorcycle_date_text_bottom">

            <ImageView
                android:layout_width="@dimen/motorcycle_date_icon_width"
                android:layout_height="@dimen/motorcycle_date_icon_height"
                android:layout_gravity="center"
                android:layout_marginStart="@dimen/motorcycle_date_icon_start"
                android:src="@drawable/ic_calendar_white"
                android:layout_marginLeft="@dimen/motorcycle_date_icon_start" />

            <TextView
                android:id="@+id/txt_to_date"
                android:layout_width="90dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginStart="@dimen/motorcycle_date_text_start"
                android:layout_marginEnd="@dimen/motorcycle_date_text_end"
                android:fontFamily="@font/inter_regular"
                android:gravity="center"
                android:lineSpacingExtra="14.0sp"
                android:text=""
                android:textColor="#ffffffff"
                android:textSize="@dimen/motorcycle_date_text"
                android:layout_marginLeft="@dimen/motorcycle_date_text_start"
                android:layout_marginRight="@dimen/motorcycle_date_text_end" />
        </LinearLayout>
    </RelativeLayout>

</RelativeLayout>

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical">


        <TextView
            android:id="@+id/txt_time_select"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"

            android:layout_gravity="center"
            android:layout_marginTop="3dp"
            android:gravity="center"
            android:lineSpacingExtra="14.0sp"
            android:padding="7.0dip"

            android:text="Please Select the Minimum booking of 2 hours"
            android:textAlignment="center"
            android:textColor="#ff4e44d8"

            android:textSize="14dp"


            />

        <com.prolificinteractive.materialcalendarview.MaterialCalendarView xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/calendarView"
            android:layout_width="fill_parent"
            android:layout_height="0.0dip"
            android:layout_below="@+id/linear_time_type"
            android:layout_centerHorizontal="true"
            android:layout_gravity="center"
            android:layout_margin="@dimen/margin_small"
            android:layout_weight="0.5"

            app:mcv_allowClickDaysOutsideCurrentMonth="true"


            app:mcv_arrowColor="#7EA2FA"
            app:mcv_selectionColor="#ff4e44d8" />

        <View
            android:id="@+id/divider"
            android:layout_width="fill_parent"
            android:layout_height="1.0dip"
            android:layout_below="@+id/calendarView"
            android:background="@color/divider" />

        <RelativeLayout
            android:id="@+id/relative_list_time_slots"
            android:layout_width="fill_parent"
            android:layout_height="0.0dip"
            android:layout_below="@+id/divider"
            android:layout_weight="0.5">

            <LinearLayout
                android:id="@+id/linear_progress_wave"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:gravity="center"
                android:orientation="vertical"
                android:visibility="gone" />
            <RelativeLayout
                android:id="@+id/txt_pick_drop_RR"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
                <TextView
                    android:id="@+id/txt_pick_up_drop"
                    android:text="Select Pick Up Time"
                    android:gravity="center"
                    android:textColor="#ff4e44d8"
                    android:textSize="16dp"
                    android:fontFamily="@font/inter_medium"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                </TextView>
            </RelativeLayout>

            <androidx.recyclerview.widget.RecyclerView
                android:layout_below="@+id/txt_pick_drop_RR"
                android:id="@+id/recyclerView_timeSlots"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_marginStart="@dimen/margin_small"
                android:layout_marginTop="@dimen/margin_small"
                android:layout_marginEnd="@dimen/margin_small"
                android:layout_marginBottom="50.0dip"
                android:scrollbars="horizontal"
                android:visibility="visible" />

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/recyclerView_timeSlots_next"
                android:layout_below="@+id/txt_pick_drop_RR"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:layout_marginStart="@dimen/margin_small"
                android:layout_marginTop="@dimen/margin_small"
                android:layout_marginEnd="@dimen/margin_small"
                android:layout_marginBottom="50.0dip"
                android:scrollbars="horizontal"
                android:visibility="gone" />
        </RelativeLayout>
    </LinearLayout>

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_above="@+id/layout_actionbtns"
        android:layout_margin="5.0dip"
        android:gravity="bottom|center|right"
        android:text="Indian Standard Time"
        android:textColor="@color/light_gray"
        android:textSize="10.0dip" />

    <LinearLayout
        android:id="@+id/layout_actionbtns"
        android:layout_width="fill_parent"
        android:layout_height="@dimen/common_btn_height"
        android:layout_alignParentStart="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal">

        <LinearLayout
            android:layout_marginLeft="10dp"
            android:id="@+id/btn_cancel"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_gravity="center"
            android:layout_weight="0.5"
            android:background="@drawable/ripple_next_button"
            android:clickable="true"
            android:foreground="@drawable/ic_ripple_white"
            android:gravity="center">

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:layout_gravity="center"
                android:gravity="center">

                <ImageView
                    android:layout_width="17.0dip"
                    android:layout_height="17.0dip"
                    android:layout_gravity="center"
                    android:src="@drawable/ic_wrong" />
            </LinearLayout>

            <TextView
                android:id="@+id/txt_cancel"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:layout_gravity="center"
                android:layout_marginLeft="10.0dip"
                android:gravity="center"
                android:text="Cancel"

                android:textColor="@color/white"
                android:textSize="18.0dip"
                android:textStyle="bold" />
        </LinearLayout>

        <View
            android:layout_width="10.0dip"
            android:layout_height="fill_parent"
            android:background="@color/white" />

        <LinearLayout
            android:layout_marginRight="10dp"
            android:id="@+id/btn_done"

            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_gravity="center"
            android:layout_weight="0.5"


            android:background="@drawable/ripple_next_button"
            android:clickable="true"



            android:foreground="@drawable/ic_ripple_white"
            android:focusable="true"

            android:gravity="center">

            <LinearLayout



                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:layout_gravity="center"


                android:gravity="center">

                <ImageView

                    android:layout_width="20.0dip"
                    android:layout_height="20.0dip"
                    android:layout_gravity="center"

                    android:src="@drawable/ic_tick" />
            </LinearLayout>

            <TextView
                android:id="@+id/txt_done"

                android:layout_width="wrap_content"
                android:layout_height="fill_parent"


                android:layout_gravity="center"

                android:layout_marginLeft="10.0dip"
                android:layout_marginRight="16.0dip"


                android:fontFamily="@font/inter_medium"
                android:gravity="center"
                android:minHeight="0.0dip"
                android:paddingStart="10.0dip"
                android:paddingEnd="10.0dip"
                android:text="NEXT"
                android:textColor="@color/white"
                android:textSize="16.0sp" />


        </LinearLayout>
    </LinearLayout>



</RelativeLayout>

这是我的Recycler视图xml文件.我想我们必须在这里进行修改以获取类似时隙的布局. 但不确定如何制作.

Here my Recycler view xml file. i guess we have to modify here to get layout like time slots. but not sure how to make.

time_slot_layout.xml

time_slot_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"

android:background="?android:attr/selectableItemBackground"
android:layout_height="wrap_content">

<TextView
    android:layout_width="match_parent"

   android:textAlignment="center"
    android:textSize="20dp"
    android:id="@+id/time_slot"
    android:layout_height="35dp">

</TextView>

推荐答案

您可以使用Android本机小部件-NumberPicker.这使您可以从预定义的范围中选择一个数字. https://stackoverflow.com/a/39662187/5742882

You may make use of Android native widget - NumberPicker. This allows you to pick a number from a predefined range. https://stackoverflow.com/a/39662187/5742882

对于动态更新, 摘录 https://github.com/drawers/SpinnerDatePicker .

For dynamic updation, take a gist of https://github.com/drawers/SpinnerDatePicker.

这也可以使用具有正确日期格式的NumberPicker.

This also makes use of NumberPicker with proper date formattings.

这篇关于如何在RecyclerView Android中添加时隙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆