繁体   English   中英

如何在Android屏幕上安装Horizo​​ntal RecyclerView可滚动项?

[英]How to fit Horizontal recyclerView scrollable items into screen in android?

我正在垂直滚动视图中加载水平recyclerView。 卧式recyclerView项目应适合屏幕且可滚动。

XMl已在nestedscrollView和水平recyclerView项目中为垂直recyclerView添加。

代码:

void bind(final Element element, final int position) {
            myCustomTextViewElementName.setText(element.getElementName() + "/" + element.getPriority());
            myCustomTextViewElementName.setTextColor(ContextCompat.getColorStateList(mContext, R.color.text_color));

        }

XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:customfontdemo="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/color_white"
    android:fitsSystemWindows="true"
    android:orientation="vertical">

    <include layout="@layout/toolbar" />

    <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/white"
        android:orientation="vertical">

        <android.support.design.widget.AppBarLayout
            android:id="@+id/main.appbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/light_grey_color"
            android:fitsSystemWindows="true">

            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/collapsingToolbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:fitsSystemWindows="true"
                app:contentScrim="@color/light_grey_color"
                app:layout_scrollFlags="scroll|exitUntilCollapsed"
                app:title="">

                <LinearLayout
                    android:id="@+id/patient_profile_layout"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@color/light_grey_color"
                    android:orientation="horizontal"
                    app:layout_behavior="@string/appbar_scrolling_view_behavior">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="@dimen/margin_16dp"
                        android:layout_marginRight="@dimen/margin_16dp"
                        android:layout_marginTop="@dimen/margin_16dp"
                        android:orientation="horizontal">

                        <com.mikhaellopez.circularimageview.CircularImageView
                            android:id="@+id/circularImageView"
                            android:layout_width="@dimen/image_size"
                            android:layout_height="@dimen/image_size"
                            android:src="@drawable/default_avatar"
                            app:civ_border="true"
                            app:civ_border_color="#3f51b5"
                            app:civ_border_width="1dp"
                            app:civ_shadow="true"
                            app:civ_shadow_color="#3f51b5" />

                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginLeft="@dimen/margin_8dp"
                            android:orientation="vertical">

                            <MyCustomTextView
                                android:id="@+id/text_view_patient_name_with_emr_number"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:textColor="@color/black_54_percent"
                                android:textSize="@dimen/text_size_14dp"
                                customfontdemo:fontName="@string/font_family_roboto_regular" />

                            <MyCustomTextView
                                android:id="@+id/text_view_patient_age"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:text="Age - 32 | Female | Married "
                                android:textColor="@color/black_color_87_percent"
                                android:textSize="@dimen/text_size_12dp"
                                customfontdemo:fontName="@string/font_family_roboto_regular" />

                            <MyCustomTextView
                                android:id="@+id/text_view_patient_id"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:text="Patient ID - "
                                android:textColor="@color/black_color_87_percent"
                                android:textSize="@dimen/text_size_12dp"
                                customfontdemo:fontName="@string/font_family_roboto_regular" />

                            <MyCustomTextView
                                android:id="@+id/text_view_hospital_name"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_marginTop="@dimen/margin_12dp"
                                android:text="Corporate- Paramount Health Services(P)"
                                android:textColor="@color/black_color_87_percent"
                                android:textSize="@dimen/text_size_12dp"
                                customfontdemo:fontName="@string/font_family_roboto_regular" />

                            <MyCustomTextView
                                android:id="@+id/text_view_consultant_name"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:text="Consultant Name- Rachan"
                                android:textColor="@color/black_color_87_percent"
                                android:textSize="@dimen/text_size_12dp"
                                customfontdemo:fontName="@string/font_family_roboto_regular" />

                            <MyCustomTextView
                                android:id="@+id/text_view_department_name"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:text="Department- Medical Oncology"
                                android:textColor="@color/black_color_87_percent"
                                android:textSize="@dimen/text_size_12dp"
                                customfontdemo:fontName="@string/font_family_roboto_regular" />

                            <MyCustomTextView
                                android:id="@+id/text_view_date_of_admission"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_marginBottom="@dimen/text_size_12dp"
                                android:layout_marginTop="@dimen/text_size_12dp"
                                android:text="Date of Admission- 5 May 17"
                                android:textColor="@color/black_color_87_percent"
                                android:textSize="@dimen/text_size_12dp"
                                customfontdemo:fontName="@string/font_family_roboto_regular" />


                        </LinearLayout>
                    </LinearLayout>
                </LinearLayout>
            </android.support.design.widget.CollapsingToolbarLayout>
        </android.support.design.widget.AppBarLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

            <MyCustomTextView
                android:id="@+id/text_view_today_date"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_gravity="center"
                android:layout_marginTop="@dimen/margin_16dp"
                android:background="@drawable/round_corner_btn"
                android:gravity="center"
                android:paddingBottom="@dimen/margin_4dp"
                android:paddingLeft="@dimen/margin_28dp"
                android:paddingRight="@dimen/margin_28dp"
                android:paddingTop="@dimen/margin_4dp"
                android:text="Today"
                android:visibility="gone"
                android:textColor="@color/color_white"
                android:textSize="@dimen/text_size_12dp"
                app:layout_behavior="@string/appbar_scrolling_view_behavior"
                customfontdemo:fontName="@string/font_family_roboto_regular" />

            <android.support.v4.widget.NestedScrollView
                android:id="@+id/nested_scroll_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_below="@+id/text_view_today_date"
                app:layout_behavior="@string/appbar_scrolling_view_behavior">

                <RelativeLayout
                    android:id="@+id/relative_layout"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="@dimen/margin_36dp"
                    android:orientation="vertical"
                    android:visibility="gone"
                    app:layout_behavior="@string/appbar_scrolling_view_behavior">

                    <android.support.v7.widget.RecyclerView
                        android:id="@+id/recyclerView"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:scrollbars="vertical" />

                    <Button
                        android:id="@+id/btn_submit"
                        android:layout_width="180dp"
                        android:layout_height="45dp"
                        android:layout_below="@+id/recyclerView"
                        android:layout_centerHorizontal="true"
                        android:layout_gravity="center"
                        android:layout_marginBottom="@dimen/margin_54dp"
                        android:layout_marginTop="@dimen/margin_16dp"
                        android:background="@color/colorPrimaryDark"
                        android:gravity="center"
                        android:text="Submit"
                        android:textAllCaps="false"
                        android:textColor="@android:color/white" />
                </RelativeLayout>
            </android.support.v4.widget.NestedScrollView>
        </RelativeLayout>
    </android.support.design.widget.CoordinatorLayout>
</LinearLayout>

卧式回收机查看项目

每个垂直recyclerView项目的水平recyclerView

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:customfontdemo="http://schemas.android.com/apk/res-auto"
    style="@style/AppTheme.Card.Margins"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/white">

    <LinearLayout
        android:id="@+id/whole_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/white"
        android:orientation="vertical">

        <MyCustomTextView
            android:id="@+id/text_view_section_list_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/margin_8dp"
            android:text="@string/text_cheif_complains"
            android:textColor="@color/black_color_20_percent"
            android:textSize="@dimen/text_size_14dp"
            customfontdemo:fontName="@string/font_family_roboto_regular" />

        <android.support.v7.widget.RecyclerView
            android:id="@+id/element_recycler_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:layout_marginTop="@dimen/margin_12dp" />

        <MyCustomTextView
            android:id="@+id/remaining_element_count"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:layout_marginLeft="@dimen/margin_4dp"
            android:layout_marginRight="@dimen/margin_12dp"
            android:layout_marginTop="@dimen/margin_5dp"
            android:gravity="left"
            android:textColor="@android:color/holo_red_dark"
            android:textSize="@dimen/text_size_14dp"
            android:visibility="gone"
            customfontdemo:fontName="@string/font_family_roboto_regular" />

        <MyCustomTextView
            android:id="@+id/text_view_add_emr"
            android:layout_width="match_parent"
            android:layout_height="@dimen/margin_40dp"
            android:layout_gravity="center"
            android:layout_marginBottom="@dimen/margin_16dp"
            android:layout_marginLeft="@dimen/margin_8dp"
            android:gravity="center|left"
            android:text="@string/text_add_more"
            android:textColor="@color/colorPrimaryDark"
            android:textSize="@dimen/text_size_14dp"
            customfontdemo:fontName="@string/font_family_roboto_regular" />

        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_marginBottom="@dimen/margin_8dp"
            android:layout_marginLeft="@dimen/margin_8dp"
            android:layout_marginRight="@dimen/margin_8dp"
            android:layout_marginTop="@dimen/margin_12dp"
            android:background="@color/black_color_20_percent"
            android:visibility="gone" />

    </LinearLayout>

</android.support.v7.widget.CardView>

在此处输入图片说明

尝试为每个元素设置布局权重1,宽度=0。然后发布您的XML代码。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM