«Уменьшить» CardView при прокрутке в другом виде - PullRequest
0 голосов
/ 26 ноября 2018

Снимок экрана

enter image description here

Как видите, макет слишком велик для старого устройства.Моя идея состоит в том, чтобы уменьшить CardView, пока пользователь прокручивает белую область (ViewPager), чтобы сделать его больше.Я видел, как это работает хорошо в другом приложении (не помню, какое).Я понятия не имею, как я могу это сделать, мне нужно написать это программно?

XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".WordActivity">

    <WebView
        android:id="@+id/webView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:elevation="20dp"
        android:visibility="gone" />

    <android.support.v7.widget.CardView
        android:id="@+id/cardView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:elevation="0dp"
        app:cardBackgroundColor="@color/primary_dark"
        app:cardCornerRadius="0dp">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:padding="5dp">

            <TextView
                android:id="@+id/wordTitle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/poweredBy"
                android:layout_centerInParent="true"
                android:layout_marginTop="-12dp"
                android:fontFamily="@font/poppins"
                android:text="@string/word_title"
                android:textColor="@android:color/white"
                android:textSize="30sp" />

            <TextView
                android:id="@+id/wordTranslated"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@id/wordTitle"
                android:layout_alignStart="@id/wordTitle"
                android:layout_marginTop="-10dp"
                android:fontFamily="@font/poppins"
                android:textColor="@android:color/darker_gray"
                android:textSize="16sp" />

            <TextView
                android:id="@+id/poweredBy"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:fontFamily="@font/bungee_hairline"
                android:text="@string/powered"
                android:textColor="@android:color/darker_gray"
                android:textSize="16sp" />

        </RelativeLayout>

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

    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/coordinatorLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/cardView">

        <android.support.design.widget.TabLayout
            android:id="@+id/tabLayout"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:background="@color/primary"
            android:elevation="5dp"
            app:tabIndicatorColor="@android:color/white"
            app:tabIndicatorHeight="2dp"
            app:tabPaddingEnd="-1dp"
            app:tabPaddingStart="-1dp"
            app:tabSelectedTextColor="@android:color/white"
            app:tabTextColor="@color/white_transparent" />

        <android.support.v4.view.ViewPager
            android:id="@+id/viewPager"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="45dp" />

    </android.support.design.widget.CoordinatorLayout>

</RelativeLayout>

Ответы [ 3 ]

0 голосов
/ 26 ноября 2018

Попробуйте этот пример макета, просто измените код внутри вложенного просмотра прокрутки с помощью табуляции

<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">

<android.support.design.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/Theme.AppCompat.Light.NoActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="true"
            app:expandedTitleTextAppearance="@android:color/transparent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="170dp"
                android:background="@drawable/bckg"
                app:layout_collapseMode="parallax"/>

            <android.support.v7.widget.Toolbar
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:clipToPadding="false"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/Theme.AppCompat.Light"/>

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

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


    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipToPadding="false"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:text="@string/textLoremIpsum"/>

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

</android.support.design.widget.CoordinatorLayout>

Вот мой пример скриншота

Сцена 1

enter image description here

Сцена 2

enter image description here

0 голосов
/ 27 ноября 2018

попробуйте еще раз с этим примером макета.

activity_main2.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   xmlns:app="http://schemas.android.com/apk/res-auto"
   android:theme="@style/Theme.AppCompat.Light.NoActionBar">

        <android.support.design.widget.AppBarLayout
            android:id="@+id/appbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/Theme.AppCompat.Light.NoActionBar">

            <android.support.design.widget.CollapsingToolbarLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:fitsSystemWindows="true"
                app:expandedTitleTextAppearance="@android:color/transparent"
                app:layout_scrollFlags="scroll|exitUntilCollapsed">

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="170dp"
                    android:background="@drawable/bckg_toolbar"
                    app:layout_collapseMode="parallax" />

                <android.support.v7.widget.Toolbar
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:clipToPadding="false"
                    app:layout_collapseMode="pin"
                    app:popupTheme="@style/Theme.AppCompat.Light" />

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

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">
                <android.support.design.widget.TabLayout
                    android:id="@+id/tabs"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="#202020"
                    app:layout_anchorGravity="top|center"
                    app:tabGravity="fill"
                    app:tabIndicatorColor="#FBA601"
                    app:tabMode="fixed"
                    app:tabSelectedTextColor="#FBA601"
                    app:tabTextColor="#fff" />
            </LinearLayout>
        </android.support.design.widget.AppBarLayout>


        <android.support.v4.view.ViewPager
            android:id="@+id/viewpager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

сцена 1

enter image description here

сцена 2

enter image description here

0 голосов
/ 26 ноября 2018

Это может быть неприменимо к вашему текущему макету, но если вы можете интегрировать сворачивающиеся панели инструментов Android , вы можете сэкономить немного времени.

В противном случае вы можете использовать что-то вроде this , чтобы определить, когда пользователь находится в верхней части вашего списка, и показать представление, скрывая его в противном случае

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...