簡體   English   中英

Android - 在Fragment中使用NestedScrollView時,FrameLayout與CoordinatorLayout重疊

[英]Android - FrameLayout is overlapped by CoordinatorLayout when use NestedScrollView inside the Fragment

我正在嘗試使CoordinatorLayout包含一個FrameLayout作為子項。 此FrameLayout稍后將替換為具有NestedScrollView父級的Fragment。

問題在於,當創建片段時,FrameLayout處於錯誤的位置,就像它有某種邊距一樣。

在下一張圖片中,我將向您展示初始位置。

初始位置

這應該是一開始的:

正確的位置

這是活動的布局

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout android:id="@+id/coordinator"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:background="@color/gray">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar_layout"
        android:layout_width="match_parent"
        android:layout_height="340dp"
        android:orientation="vertical">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/ctlLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

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

                <TextView
                    android:id="@+id/beer_style"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="European Lagers"
                    android:textColor="@color/gray"
                    android:textSize="16sp"/>

                <TextView
                    android:id="@+id/beer_name"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Birra Peroni"
                    android:textColor="@color/white"
                    android:textSize="24sp"/>

                <de.hdodenhof.circleimageview.CircleImageView
                    xmlns:app="http://schemas.android.com/apk/res-auto"
                    android:id="@+id/beer_image"
                    android:layout_width="120dp"
                    android:layout_height="120dp"
                    android:layout_margin="16dp"
                    android:src="@mipmap/logo"
                    app:civ_border_width="2dp"
                    app:civ_border_color="#FF000000"/>

                <com.iarcuschin.simpleratingbar.SimpleRatingBar
                    android:id="@+id/rating_bar"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    app:srb_starSize="28dp"
                    app:srb_numberOfStars="5"
                    app:srb_stepSize="0.5"
                    app:srb_borderColor="@color/black"
                    app:srb_fillColor="@color/gray"
                    app:srb_starCornerRadius="20"/>

            </LinearLayout>

            <!-- Toolbar -->
            <include android:id="@+id/toolbar"
                layout="@layout/toolbar" />
        </android.support.design.widget.CollapsingToolbarLayout>

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

    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginEnd="8dp"
        app:behavior_overlapTop="60dp"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

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

這是我在FrameLayout中替換的布局

<android.support.v4.widget.NestedScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="jdeveloper.coriassos.views.fragments.BeerDetailFragment">

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/corner_layout"
        android:orientation="vertical"
        android:layout_margin="8dp">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/information"
            android:textColor="@color/black"
            android:textSize="20sp"
            android:layout_marginTop="16dp"
            android:layout_marginLeft="16dp"
            android:layout_marginStart="16dp"
            android:layout_marginBottom="8dp"/>

        <TextView
            android:id="@+id/beer_description"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/lore_ipsum"
            android:textColor="@color/gray"
            android:layout_marginLeft="16dp"
            android:layout_marginStart="16dp"
            android:layout_marginRight="16dp"
            android:layout_marginEnd="16dp"/>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_gravity="right"
            android:layout_margin="16dp">

            <TextView
                android:id="@+id/beer_origin"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="California, USA"
                android:textColor="@color/gray"/>

            <TextView
                android:id="@+id/beer_abv"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Alc. 5,00%"
                android:textColor="@color/gray"/>

        </LinearLayout>

    </LinearLayout>

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginBottom="1dp"
        android:background="@drawable/corner_top_layout">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/available"
            android:textColor="@color/black"
            android:textSize="20sp"
            android:layout_margin="16dp"/>

    </FrameLayout>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/variant_recycler_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginRight="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginStart="8dp" />

</LinearLayout>

降低價值

app:behavior_overlapTop="60dp" 

在你的FrameLayout中

暫無
暫無

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

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