【问题标题】:How to add an ImageView below AppBarLayout under CoordinatorLayout?如何在CoordinatorLayout下的AppBarLayout下添加ImageView?
【发布时间】:2016-11-30 15:47:37
【问题描述】:

我通过添加android:layout_marginTop="112dp" 实现了这一点,有没有其他方法可以像我们在RelativeLayout 中那样让我的ImageView 刚好低于AppBarLayout

另外,我希望这个 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" />

请检查此图片:

【问题讨论】:

  • 只需将ImageView insideAppBarLayout 放在Toolbar 下方即可。
  • 这将扩展AppBarLayout 的背景,这不是我想要实现的。我附上了一张图片来显示我想要得到的结果。谢谢!

标签: android android-layout android-imageview android-coordinatorlayout android-appbarlayout


【解决方案1】:

另外,我希望这个 ImageView 具有与 AppBarLayout 有所以图像会显示为 应用栏布局。

可以通过在其中添加 CardViewImageView 或其他方式来实现,但是,如果您希望两者都有阴影,则可能需要删除 AppBarLayout 阴影,因为那里将是ImageViewAppBarLayout 之间的阴影,看起来不太好。

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

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

app:layout_behavior="@string/appbar_scrolling_view_behavior"

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

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

发送至TextViewget 以完成它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-09
    • 2020-11-16
    • 2015-12-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多