如何在ScrollView的屏幕底部对齐TextView + RecyclerView? [英] How to align TextView + RecyclerView at screen bottom within ScrollView?

查看:85
本文介绍了如何在ScrollView的屏幕底部对齐TextView + RecyclerView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Fragment中有XML文件的下一个结构.我对RelativeLayout 3(id = referralsContainer)有问题.它由textView(id = inviteText)+ RecyclerView(id = rv_referrals)组成.我需要以任何分辨率在屏幕底部显示textView.之后,textView必须是带有元素的RecyclerView(当用户向下滚动时).我尝试在方法中执行类似的操作,当加载了recyclerview的所有元素,但是不时地将Y轴替换为recyclerview的不同位置时,我不明白如何正确地将textview放置在屏幕底部. ScrollView还削减了recyclerView的几项.有人可以帮忙吗?调试器中的所有位置看起来都正确. Code + xml在图像下方.谢谢.

I have the next structure of XML file in my Fragment. I have an issue with RelativeLayout 3 (id=referralsContainer). It consist of textView (id=inviteText) + RecyclerView (id=rv_referrals). I need to show textView at the bottom of screen with any resolution. And after that textView must be RecyclerView with elements (when user will scroll down). I tried to do something like this in method, when all elements of recyclerview loaded, but recyclerview is replaced in different positions by Y axe from time to time, I can't understand how to correctly place that textview at the bottom of the scrren. And also ScrollView cuts several items of recyclerView. Does anybody can help with this? All positions in debugger looks right. Code+xml is below image. Thanks.

this.dataSourceListForAdapter.addAll(incomeListOfItemsFromServer);
recyclerView.setY(scrollView.getBottom() - textView.getHeight());
recyclerView.setY(coordinatorView.getBottom() - textView.getHeight());
adapter.notifyDataSetChanged();


<?xml version="1.0" encoding="utf-8"?>

<android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/invite_friends_swipe_refresh"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

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

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <RelativeLayout
                    android:id="@+id/invite_friends_content_part"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@color/white"
                    android:visibility="visible">

                    <RelativeLayout
                        android:id="@+id/invite_friends_container"
                        android:layout_width="match_parent"
                        android:layout_height="190dp"
                        android:layout_alignParentTop="true"
                        android:background="@color/re_black_light_new">

                        <TextView
                            android:id="@+id/invite_friends_text"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:layout_above="@+id/invite_friends_button_container"
                            android:gravity="center"
                            android:paddingEnd="40dp"
                            android:paddingStart="40dp"
                            android:textColor="@color/white"
                            android:textSize="16sp"
                            tools:text="@string/friends_invite_message" />

                        <RelativeLayout
                            android:id="@+id/invite_friends_button_container"
                            android:layout_width="match_parent"
                            android:layout_height="60dp"
                            android:layout_alignParentBottom="true">

                            <View
                                android:layout_width="match_parent"
                                android:layout_height="40dp"
                                android:layout_alignParentTop="true"
                                android:layout_marginTop="2dp"
                                android:background="@drawable/combined_shape_white" />

                            <View
                                android:layout_width="match_parent"
                                android:layout_height="20dp"
                                android:layout_alignParentBottom="true"
                                android:background="@color/white" />

                            <android.support.v7.widget.CardView
                                android:id="@+id/invite_friends_button_invite"
                                android:layout_width="147dp"
                                android:layout_height="40dp"
                                android:layout_alignParentTop="true"
                                android:layout_centerHorizontal="true"
                                android:layout_gravity="center"
                                android:layout_marginTop="10dp"
                                card_view:cardBackgroundColor="@color/white"
                                card_view:cardCornerRadius="3dp"
                                card_view:cardElevation="2dp"
                                card_view:cardPreventCornerOverlap="false"
                                card_view:cardUseCompatPadding="true">

                                <TextView
                                    android:id="@+id/invite_friends_button_invite_text"
                                    android:layout_width="match_parent"
                                    android:layout_height="match_parent"
                                    android:background="@drawable/yellow_button_selector"
                                    android:clickable="true"
                                    android:focusable="true"
                                    android:fontFamily="sans-serif-medium"
                                    android:gravity="center"
                                    android:text="@string/friends_invite"
                                    android:textAllCaps="true"
                                    android:textColor="@color/re_black_light_new"
                                    android:textSize="14sp" />

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

                        </RelativeLayout>

                    </RelativeLayout>

                    <TextView
                        android:id="@+id/copy_choice_label"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/invite_friends_container"
                        android:layout_centerHorizontal="true"
                        android:textSize="12sp"
                        android:text="@string/copy_link_text"
                        android:textColor="@color/re_gray_new" />

                    <RelativeLayout
                        android:id="@+id/invite_friends_referal_link_button"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/copy_choice_label"
                        android:layout_marginLeft="20dp"
                        android:layout_marginRight="20dp"
                        android:layout_marginTop="16dp"
                        android:background="@drawable/rectangle_gray">

                        <TextView
                            android:id="@+id/invite_friends_referal_link_text"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:layout_centerVertical="true"
                            android:background="?attr/selectableItemBackground"
                            android:clickable="true"
                            android:focusable="true"
                            android:fontFamily="sans-serif-light"
                            android:gravity="center"
                            android:padding="7dp"
                            android:textColor="@color/re_black_light"
                            android:textSize="12sp" />

                    </RelativeLayout>

                    <RelativeLayout
                        android:id="@+id/invite_friends_full_info_container"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_below="@+id/invite_friends_referal_link_button"
                        android:layout_marginTop="32dp">

                        <RelativeLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginEnd="10dp"
                            android:layout_marginStart="24dp"
                            android:layout_toLeftOf="@+id/invite_friends_container_central"
                            android:gravity="center_vertical">

                            <TextView
                                android:id="@+id/invite_friends_text_friends"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:fontFamily="sans-serif-medium"
                                android:text="@string/friends_invite_friends"
                                android:textColor="@color/re_black_light_new"
                                android:textSize="12sp" />

                            <TextView
                                android:id="@+id/invite_friends_friends_count"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:layout_below="@+id/invite_friends_text_friends"
                                android:layout_marginTop="4dp"
                                android:fontFamily="sans-serif-medium"
                                android:textColor="@color/re_black_light_new"
                                android:textSize="24sp"
                                tools:text="4" />

                            <View
                                android:id="@+id/invite_friends_divider_horizontal"
                                android:layout_width="match_parent"
                                android:layout_height="1dp"
                                android:layout_below="@+id/invite_friends_friends_count"
                                android:layout_marginTop="8dp"
                                android:background="@drawable/dash_horizontal_gray"
                                android:layerType="software" />

                            <TextView
                                android:id="@+id/invite_friends_text_orders"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:layout_alignParentEnd="true"
                                android:layout_below="@+id/invite_friends_divider_horizontal"
                                android:layout_marginTop="14dp"
                                android:fontFamily="sans-serif-medium"
                                android:text="@string/friends_invite_orders"
                                android:textColor="@color/re_black_light_new"
                                android:textSize="12sp" />

                            <TextView
                                android:id="@+id/invite_friends_orders_count"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:layout_below="@+id/invite_friends_text_orders"
                                android:layout_marginTop="4dp"
                                android:fontFamily="sans-serif-medium"
                                android:textColor="@color/re_black_light_new"
                                android:textSize="24sp"
                                tools:text="32" />

                        </RelativeLayout>

                        <View
                            android:id="@+id/invite_friends_container_central"
                            android:layout_width="1dp"
                            android:layout_height="1dp"
                            android:layout_centerInParent="true"
                            android:background="@drawable/dotted_line"
                            android:layerType="software" />

                        <RelativeLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginEnd="16dp"
                            android:layout_marginStart="10dp"
                            android:layout_toRightOf="@+id/invite_friends_container_central">

                            <TextView
                                android:id="@+id/invite_friends_income_text"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:layout_alignParentStart="true"
                                android:layout_alignParentTop="true"
                                android:layout_marginStart="6dp"
                                android:fontFamily="sans-serif-medium"
                                android:text="@string/friends_invite_income"
                                android:textColor="@color/re_black_light_new"
                                android:textSize="12sp" />

                            <LinearLayout
                                android:id="@+id/invite_friends_income_container"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_below="@+id/invite_friends_income_text"
                                android:layout_marginTop="4dp"
                                android:orientation="horizontal">

                                <TextView
                                    android:id="@+id/invite_friends_income_count"
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:layout_marginStart="6dp"
                                    android:fontFamily="sans-serif-medium"
                                    android:lines="1"
                                    android:maxLines="1"
                                    android:textColor="@color/re_black_light_new"
                                    android:textSize="24sp"
                                    tools:text="1488.77" />

                                <TextView
                                    android:id="@+id/invite_friends_income_currency"
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:layout_marginStart="5dp"
                                    android:fontFamily="sans-serif-medium"
                                    android:lines="1"
                                    android:maxLines="1"
                                    android:textColor="@color/re_black_light_new"
                                    android:textSize="12sp"
                                    tools:text="руб." />

                            </LinearLayout>

                            <View
                                android:id="@+id/invite_friends_divider_horizontal_2"
                                android:layout_width="match_parent"
                                android:layout_height="1dp"
                                android:layout_below="@+id/invite_friends_income_container"
                                android:layout_marginEnd="16dp"
                                android:layout_marginTop="8dp"
                                android:background="@drawable/dash_horizontal_gray"
                                android:layerType="software" />

                            <TextView
                                android:id="@+id/invite_friends_text_income_pending"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:layout_below="@+id/invite_friends_divider_horizontal_2"
                                android:layout_marginStart="6dp"
                                android:layout_marginTop="14dp"
                                android:fontFamily="sans-serif-medium"
                                android:text="@string/friends_invite_income_pending"
                                android:textColor="@color/re_black_light"
                                android:textSize="12sp" />

                            <LinearLayout
                                android:id="@+id/invite_friends_text_income_pending_container"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"
                                android:layout_below="@+id/invite_friends_text_income_pending"
                                android:layout_marginStart="6dp"
                                android:layout_marginTop="4dp"
                                android:orientation="horizontal">

                                <TextView
                                    android:id="@+id/invite_friends_text_income_pending_count"
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:fontFamily="sans-serif-medium"
                                    android:textColor="@color/re_gray_new"
                                    android:textSize="24sp"
                                    tools:text="0" />

                                <TextView
                                    android:id="@+id/invite_friends_text_income_pending_count_currency"
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:layout_marginStart="5dp"
                                    android:fontFamily="sans-serif-medium"
                                    android:lines="1"
                                    android:maxLines="1"
                                    android:textColor="@color/re_gray_new"
                                    android:textSize="12sp"
                                    tools:text="руб."/>

                            </LinearLayout>

                        </RelativeLayout>

                    </RelativeLayout>

                </RelativeLayout>

                <RelativeLayout
                    android:id="@+id/referralsContainer"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@id/invite_friends_content_part"
                    android:visibility="gone"
                    android:orientation="vertical">

                    <TextView
                        android:id="@+id/inviteText"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerHorizontal="true"
                        android:layout_marginTop="30dp"
                        android:fontFamily="sans-serif-medium"
                        android:text="Вы уже пригласили:"
                        android:textColor="@color/re_black_light_new"
                        android:textSize="20sp"
                        android:textStyle="normal" />

                    <ImageView
                        android:id="@+id/scrollMore"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_below="@id/inviteText"
                        android:layout_centerHorizontal="true"
                        android:layout_marginBottom="6dp"
                        android:layout_marginTop="6dp"
                        android:src="@drawable/ic_scroll_more" />

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

            </RelativeLayout>

            <LinearLayout
                android:id="@+id/invite_friends_error_part"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@color/white"
                android:gravity="center"
                android:orientation="vertical"
                android:visibility="gone">

                <ImageView
                    android:id="@+id/error_image"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="50dp"
                    android:layout_marginRight="50dp"
                    android:layout_marginTop="20dp"
                    android:scaleType="fitCenter"
                    android:src="@drawable/lost_connection_holder" />

                <TextView
                    android:id="@+id/error_text"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/error_image"
                    android:layout_marginBottom="60dp"
                    android:layout_marginTop="10dp"
                    android:gravity="center_horizontal"
                    android:paddingLeft="20dp"
                    android:paddingRight="20dp"
                    android:text="@string/no_connection_message"
                    android:textColor="@color/black_tr_38"
                    android:textSize="19sp" />

            </LinearLayout>

        </RelativeLayout>

    </ScrollView>

</android.support.v4.widget.SwipeRefreshLayout>

推荐答案

ScrollView不适用于与屏幕底部对齐的子子布局,因为其直接子级不知道底部在哪里.从您的问题尚不清楚,您如何(想要)滚动底部.

ScrollView is not purposed for sub-child layouts aligned to the bottom of screen as its direct child doesn't know where the bottom is. From your question is not clear how do you need (want) to scroll bottom part.

如果可以通过拖动底部部分(RelativeLayout 3)进行滚动,则最好使用 BottomSheetBehaviour .

If it is ok to scroll by dragging bottom part (RelativeLayout 3) it is better to use BottomSheetBehaviour in Coordinatorlayout for this layout.

如果没有,那么只需将RelativeLayout 3放在SwipeRefreshLayout(下方)下,并处理ScrollView scrollChanged事件,以动画化底部布局的滚动,如果需要或仅显示/隐藏此底部布局.

If not then just put RelativeLayout 3 under (below) SwipeRefreshLayout and handle ScrollView scrollChanged events to animate scrolling of bottom layout if you need or just show/hide this bottom layout.

请不要忘记,在较小的分辨率下,与底部对齐的布局将覆盖ScrollView的内容,并且用户将无法滚动顶部的布局.

Don't forget that on small resolutions layout aligned to the bottom will cover the content of ScrollView and user won't be able to scroll top layout.

这篇关于如何在ScrollView的屏幕底部对齐TextView + RecyclerView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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