如何在CoordinatorLayout下的AppBarLayout下面添加一个ImageView?

问题描述 投票:0回答:1

我通过添加android:layout_marginTop="112dp"来实现这一点,有没有其他方法让我的ImageView在AppBarLayout下方,就像我们在RelativeLayout中一样?

此外,我希望这个ImageView具有与AppBarLayout相同的阴影,因此图像将显示为AppBarLayout的一部分。

我希望TextView出现在LinearLayout的图像下方。

主要活动XML

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingTop="@dimen/appbar_padding_top"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|enterAlways"
        app:popupTheme="@style/AppTheme.PopupOverlay">

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

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

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

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="112dp"
    android:orientation="horizontal">

    <ImageView
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:src="@drawable/under_tabs_triangle"/>
</LinearLayout>

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

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="end|bottom"
    android:layout_margin="@dimen/fab_margin"
    app:srcCompat="@android:drawable/ic_dialog_email" />

片段主XML

<RelativeLayout 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="com.example.dexbyte.player.MainActivity$PlaceholderFragment">

<TextView
    android:id="@+id/section_label"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

请检查此图片:

enter image description here

android android-layout android-imageview android-coordinatorlayout android-appbarlayout
1个回答
0
投票

此外,我希望此ImageView具有与AppBarLayout相同的阴影,因此图像将显示为AppBarLayout的一部分。

它可以通过在其中添加CardViewImageView或其他方式来实现,但是,如果你想要两者都有阴影,你可能需要删除AppBarLayout阴影,因为ImageViewAppBarLayout之间会有阴影看起来不太好看。

我希望TextView出现在LinearLayout的图像下方。

TextView实际上显示在正确的位置,因为你已添加:

app:layout_behavior="@string/appbar_scrolling_view_behavior"

ViewPager。所以,一切都很好。要实现您的目标,您可以添加:

android:layout_marginTop="30dp" <!-- Or more ... -->

TextViewget完成它。

© www.soinside.com 2019 - 2024. All rights reserved.