0

Сделал весь интерфейс приложения в основном RelativeLayout. В нем уже всё делал по блокам LinearLayout в одном из блоков находится RecyclerView.

Будем обозначать так:

  • LinearLayout1 - верхний блок.
  • LinearLayout2 - блок находящийся под LinearLayout1.

Не могу сделать так чтобы при скроллинге RecyclerView, LinearLayout2 двигался под LinearLayout1. Явный пример есть, при листании ленты в приложении ВКонтакте. Когда Истории и блок на историями уходять за экран.

Описание на скрине

Код того что я пробовал:

final int[] heightStart = new int[1];
        final int[] height = new int[1];
        final LinearLayout linearLayout1 = findViewById(R.id.vip_ads_container);
        linearLayout1.post(new Runnable() {
            @Override
            public void run() {
                heightStart[0] = linearLayout1.getHeight();
                height[0] = heightStart[0];
            }
        });
    commonAdsrecyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            if (dy > 0){
                animateNavigation(true);
                LinearLayout linearLayout1 = findViewById(R.id.vip_ads_container);
                LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) linearLayout1.getLayoutParams();
                layoutParams.height = height[0] - 1;
            } else {
                animateNavigation(false);
                LinearLayout linearLayout2 = findViewById(R.id.vip_ads_container);
                LinearLayout.LayoutParams layoutParams1 = (LinearLayout.LayoutParams) linearLayout2.getLayoutParams();
                layoutParams1.height = height[0] + 1;
            }
        }
    });

Мой xml, по id надо двигать vip_ads_container под background_top_conteiner так как top_main_conteiner лежит в нем:

<RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="kz.sferagroup.fromcaappication.MainActivity" android:background="#EDEDED">
&lt;com.google.android.material.bottomnavigation.BottomNavigationView
        android:layout_width=&quot;match_parent&quot;
        android:layout_height=&quot;50dp&quot; android:id=&quot;@+id/bottom_navigation_view&quot;
        android:layout_alignParentBottom=&quot;true&quot;
        app:itemIconTint=&quot;@color/select_btn_bottom_novigation_view&quot;
        app:itemTextColor=&quot;@color/select_btn_bottom_novigation_view&quot;
        app:menu=&quot;@menu/menu_bottom_navigation_view&quot; app:itemHorizontalTranslationEnabled=&quot;false&quot;
        android:background=&quot;@drawable/bc_btn_nav_view&quot;/&gt;
&lt;LinearLayout
        android:orientation=&quot;vertical&quot;
        android:layout_width=&quot;match_parent&quot;
        android:layout_height=&quot;wrap_content&quot; android:id=&quot;@+id/main_conteiner&quot; android:background=&quot;#00FFFFFF&quot;&gt;

    &lt;LinearLayout
            android:orientation=&quot;vertical&quot;
            android:layout_width=&quot;match_parent&quot;
            android:layout_height=&quot;wrap_content&quot; android:gravity=&quot;top&quot; android:id=&quot;@+id/main_conteiner2&quot;&gt;

        &lt;LinearLayout
                android:orientation=&quot;vertical&quot;
                android:layout_width=&quot;match_parent&quot;
                android:layout_height=&quot;wrap_content&quot; android:id=&quot;@+id/background_top_conteiner&quot;
                android:background=&quot;@color/vip_ads_container&quot;&gt;

            &lt;LinearLayout
                    android:orientation=&quot;vertical&quot;
                    android:layout_width=&quot;match_parent&quot;
                    android:layout_height=&quot;wrap_content&quot; android:id=&quot;@+id/top_main_conteiner&quot;
                    android:paddingTop=&quot;25dp&quot;
                    android:background=&quot;@drawable/top_main_container&quot; android:paddingBottom=&quot;25dp&quot;
                    android:paddingStart=&quot;15dp&quot; android:paddingEnd=&quot;15dp&quot;&gt;

                &lt;LinearLayout
                        android:orientation=&quot;horizontal&quot;
                        android:layout_width=&quot;match_parent&quot;
                        android:layout_height=&quot;wrap_content&quot; android:id=&quot;@+id/search_btn_conteiner&quot;
                        android:background=&quot;@drawable/btn_search&quot;&gt;
                    &lt;ImageView
                            android:layout_width=&quot;21dp&quot;
                            android:layout_height=&quot;21dp&quot; app:srcCompat=&quot;@drawable/search&quot;
                            android:id=&quot;@+id/img_search&quot; android:layout_marginStart=&quot;15dp&quot;
                            android:layout_marginTop=&quot;15dp&quot; android:layout_marginBottom=&quot;15dp&quot;
                            app:tint=&quot;@color/notactiv_text_button&quot;/&gt;
                    &lt;TextView
                            android:text=&quot;Поиск...&quot;
                            android:layout_width=&quot;wrap_content&quot;
                            android:layout_height=&quot;wrap_content&quot; android:id=&quot;@+id/text_search_btn&quot;
                            android:fontFamily=&quot;@font/roboto&quot; android:textSize=&quot;20sp&quot;
                            android:textColor=&quot;@color/notactiv_text_button&quot; android:layout_marginStart=&quot;15dp&quot;
                            android:layout_marginTop=&quot;10dp&quot; android:layout_marginBottom=&quot;14dp&quot;/&gt;
                &lt;/LinearLayout&gt;

                &lt;LinearLayout
                        android:orientation=&quot;horizontal&quot;
                        android:layout_width=&quot;match_parent&quot;
                        android:layout_height=&quot;wrap_content&quot; android:id=&quot;@+id/btn_top_conteiner&quot;
                        android:layout_marginTop=&quot;25dp&quot;&gt;
                    &lt;LinearLayout
                            android:orientation=&quot;horizontal&quot;
                            android:layout_width=&quot;wrap_content&quot;
                            android:layout_height=&quot;wrap_content&quot;
                            android:background=&quot;@drawable/activ_botton_top_container&quot;
                            android:id=&quot;@+id/all_ads_top_conteiner&quot; android:gravity=&quot;center&quot;
                    &gt;
                        &lt;ImageView
                                android:layout_width=&quot;21dp&quot;
                                android:layout_height=&quot;21dp&quot;
                                android:id=&quot;@+id/all_img_btn_top&quot;
                                android:layout_marginStart=&quot;10dp&quot; android:layout_marginTop=&quot;8dp&quot;
                                android:layout_marginBottom=&quot;8dp&quot;
                                app:srcCompat=&quot;@drawable/activ_all_img_button&quot;/&gt;
                        &lt;TextView
                                android:text=&quot;Все&quot;
                                android:layout_width=&quot;wrap_content&quot;
                                android:layout_height=&quot;wrap_content&quot; android:id=&quot;@+id/text_all_top_btn&quot;
                                android:textSize=&quot;20dp&quot; android:fontFamily=&quot;@font/roboto&quot;
                                android:layout_marginStart=&quot;10dp&quot; android:layout_marginEnd=&quot;10dp&quot;
                                android:layout_marginTop=&quot;8dp&quot; android:layout_marginBottom=&quot;8dp&quot;
                                android:textColor=&quot;@color/activ_text_button&quot;/&gt;
                    &lt;/LinearLayout&gt;
                    &lt;LinearLayout
                            android:orientation=&quot;horizontal&quot;
                            android:layout_width=&quot;wrap_content&quot;
                            android:layout_height=&quot;wrap_content&quot;
                            android:background=&quot;@drawable/not_activ_botton_top_container&quot;
                            android:id=&quot;@+id/category_top_conteiner&quot; android:gravity=&quot;center&quot;
                            android:layout_marginLeft=&quot;5dp&quot;&gt;
                        &lt;ImageView
                                android:layout_width=&quot;21dp&quot;
                                android:layout_height=&quot;21dp&quot; app:srcCompat=&quot;@drawable/list_category&quot;
                                android:id=&quot;@+id/categoty_img_btn_top&quot;
                                android:layout_marginStart=&quot;10dp&quot; android:layout_marginTop=&quot;8dp&quot;
                                android:layout_marginBottom=&quot;8dp&quot; app:tint=&quot;@color/notactiv_text_button&quot;/&gt;
                        &lt;TextView
                                android:text=&quot;Категории&quot;
                                android:layout_width=&quot;wrap_content&quot;
                                android:layout_height=&quot;wrap_content&quot; android:id=&quot;@+id/text_category_top_btn&quot;
                                android:textSize=&quot;20dp&quot; android:fontFamily=&quot;@font/roboto&quot;
                                android:layout_marginStart=&quot;10dp&quot; android:layout_marginEnd=&quot;10dp&quot;
                                android:layout_marginTop=&quot;8dp&quot; android:layout_marginBottom=&quot;8dp&quot;
                                android:textColor=&quot;@color/notactiv_text_button&quot;/&gt;
                    &lt;/LinearLayout&gt;
                &lt;/LinearLayout&gt;

            &lt;/LinearLayout&gt;
        &lt;/LinearLayout&gt;
        &lt;LinearLayout
                android:orientation=&quot;vertical&quot;
                android:layout_width=&quot;match_parent&quot;
                android:layout_height=&quot;wrap_content&quot; android:id=&quot;@+id/vip_ads_container&quot;
                android:background=&quot;@drawable/vip_ads_container&quot;
                android:paddingBottom=&quot;25dp&quot; android:paddingTop=&quot;25dp&quot;
                android:addStatesFromChildren=&quot;false&quot;&gt;

            &lt;LinearLayout
                    android:orientation=&quot;horizontal&quot;
                    android:layout_width=&quot;match_parent&quot;
                    android:layout_height=&quot;wrap_content&quot; android:id=&quot;@+id/text_vip_ads_conteiner&quot;
                    android:paddingStart=&quot;15dp&quot;&gt;
                &lt;TextView
                        android:text=&quot;VIP Объявления&quot;
                        android:layout_width=&quot;wrap_content&quot;
                        android:layout_height=&quot;wrap_content&quot; android:id=&quot;@+id/textView2&quot;
                        android:fontFamily=&quot;@font/roboto&quot; android:textStyle=&quot;bold&quot; android:textSize=&quot;26sp&quot;
                        android:textColor=&quot;@color/color__text_&quot;/&gt;
            &lt;/LinearLayout&gt;

            &lt;LinearLayout
                    android:orientation=&quot;horizontal&quot;
                    android:layout_width=&quot;match_parent&quot;
                    android:layout_height=&quot;wrap_content&quot; android:id=&quot;@+id/vip_ads_view_scroll&quot;
                    android:layout_marginTop=&quot;15dp&quot;&gt;
                &lt;androidx.recyclerview.widget.RecyclerView
                        android:layout_width=&quot;match_parent&quot;
                        android:layout_height=&quot;200dp&quot;
                        android:id=&quot;@+id/vip_ads_recyclerview&quot;
                        android:orientation=&quot;horizontal&quot;
                        app:layout_constraintStart_toStartOf=&quot;parent&quot;
                        app:layout_constraintEnd_toEndOf=&quot;parent&quot;
                        app:layout_constraintBottom_toBottomOf=&quot;@+id/imageView6&quot;
                        app:layout_constraintTop_toBottomOf=&quot;@+id/imageView3&quot;
                        app:layout_constraintVertical_bias=&quot;0.6&quot;
                        android:paddingLeft=&quot;15dp&quot;
                        tools:listitem=&quot;@layout/maket_vip_ads&quot;&gt;&lt;/androidx.recyclerview.widget.RecyclerView&gt;
            &lt;/LinearLayout&gt;

CellTonus
  • 16
  • 3
  • Добавил, такое подойдет? – CellTonus Jan 13 '21 at 12:36
  • я только зарегистрировался тут – CellTonus Jan 13 '21 at 12:41
  • Исправил, теперь мне помогут? с таким вопросом? Только проблема не могу видео загрузить – CellTonus Jan 13 '21 at 12:59
  • оно всё находится в RelativeLayout, в котором лежит главный LinearLayout, сейчас приложу xml если так получится, если нет то кусок кода. – CellTonus Jan 13 '21 at 13:05
  • Ну в общем, я сделал всё так как вы посоветовали. Спасибо) – CellTonus Jan 13 '21 at 13:13
  • Если не должно происходить каких-то сложных анимаций, то можно Vip объявления поместить также в RecyclerView - скролиться всё будет одновременно – ЮрийСПб Jan 13 '21 at 14:39
  • А можешь подсказать как это сделать? – CellTonus Jan 13 '21 at 16:10
  • 1
    Вот тут довольно подробно описано: https://ru.stackoverflow.com/a/510887/17609 – ЮрийСПб Jan 13 '21 at 19:37
  • Не особо я то и понял – CellTonus Jan 14 '21 at 07:16
  • Мне данный вариант наверно не подходит – CellTonus Jan 14 '21 at 08:43
  • Что именно вы не поняли? Сложно ещё более подробно объяснить. И почему вы думаете, что вариант этот вам не подходит? – ЮрийСПб Jan 14 '21 at 09:29
  • Потому-что, мне надо при прокрутке оставлять TextView с тестом "Все объявления" сверху после пролистывания блока "VIP Объявления" – CellTonus Jan 15 '21 at 05:10
  • Попробуйте тогда AppBarLayout c CollapsingToolbarLayout для Vip объявлений, обернув всё это в CoordinatorLayout. – ЮрийСПб Jan 15 '21 at 09:16

0 Answers0