簡體   English   中英

具有NestedScrollView行為的CoordinatorLayout

[英]CoordinatorLayout with NestedScrollView behavior

我是一名Android新手程序員,並且遇到UI問題。 我的目標是實現更接近於此的目標: 理想的布局

我考慮了一下,因此決定使用CoordinatorLayout,AppBarLayout / CollapsingToolbarLayout和帶有CardView的NestedScrollView來實現。 聽起來對這個問題很好,對吧?

使用我的實際XML,我已經具有工具欄,圖像和滾動功能。

但是,滾動功能並不是我想要的100%。 首先,由於在中間屏幕周圍(可能是由於android:layout_height="275dp" ),因此無法向下滾動,只能向上滾動。 (當然也可以折疊工具欄)。 我的主要目標是“全屏”打開圖像。 您是否知道我該如何實現這種行為? 也許在.java中控制%?

也有一個令人討厭的錯誤,但是我現在可以離開,如果它也給您一些強迫症,請嘗試提供幫助

我試圖向我的LinearLayout添加一個透明屬性,但是它不起作用。

普通滾動: 當前滾動

越野車“面板”即將崩潰: 越野車面板圖像

我所有的XML:

<android.support.design.widget.CoordinatorLayout
    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:id="@+id/annonce.main.coordinator"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:ignore="RtlHardcoded"
    >

    <android.support.design.widget.AppBarLayout
        android:id="@+id/flexible.example.appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        >

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/flexible_example_collapsing"
            android:layout_width="match_parent"
            android:layout_height="275dp"
            app:title="Mosteiro dos Jerónimos"
            app:expandedTitleMarginBottom="94dp"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:expandedTitleTextAppearance="@style/CollapsingTextAppearance.Inverse"
            app:contentScrim="?attr/colorPrimary"
            >

            <ImageView
                android:layout_width="fill_parent"
                android:layout_height="match_parent"
                android:src="@drawable/mosteiro_dos_jeronimos"
                android:scaleType="centerCrop"
                />

            <android.support.v7.widget.Toolbar
                android:id="@+id/flexible.example.toolbar"
                android:layout_width="match_parent"
                android:layout_height="30dp"
                android:background="@null"
                app:layout_collapseMode="pin"
                app:title="Mosteiro dos Jerónimos"
                style="@style/ToolBarWithNavigationBack"
                />
        </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:scrollbars="none"
        app:behavior_overlapTop="78dp"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        >

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

            <android.support.v7.widget.CardView
                android:id="@+id/flexible.example.cardview"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:contentPaddingBottom="16dp"
                app:contentPaddingLeft="16dp"
                app:contentPaddingRight="16dp"
                app:cardCornerRadius="16dp"
                app:cardBackgroundColor="@android:color/white"
                app:cardElevation="4dp"
                >

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    >

                    <View
                        android:id="@+id/myRectangleView"
                        android:layout_width="40dp"
                        android:layout_height="4dp"
                        android:layout_gravity="center"
                        android:layout_marginTop="4dp"
                        android:background="@drawable/rectangle"/>

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="Lisboa"
                        android:textAppearance="@style/TextAppearance.Header"
                        style="@style/TextComponent.ItemRow"
                        />

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:fontFamily="sans-serif-light"
                        android:lineSpacingExtra="8dp"
                        android:textSize="16sp"
                        android:text="@string/lorem"
                        />
                </LinearLayout>
            </android.support.v7.widget.CardView>
        </LinearLayout>
    </android.support.v4.widget.NestedScrollView>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/flexible.example.fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="32dp"
        android:elevation="8dp"
        android:src="@drawable/ic_adb_24dp"
        app:layout_anchor="@id/flexible.example.cardview"
        app:layout_anchorGravity="top|right|end"
        tools:ignore="RtlHardcoded"
        />
</android.support.design.widget.CoordinatorLayout>

我認為您的布局很好(可以在我這邊工作),但也許您想要的行為更像是Bottomsheet行為。

你看過了嗎?

基本上,這將使您能夠使用類似Google Maps的功能,因此可以隨意滾動。

這是一個可以更好地了解其外觀的教程。

請讓我知道這是否是您想要的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM