【问题标题】:Place an image partially above toolbar将图像部分放在工具栏上方
【发布时间】:2015-09-17 17:22:03
【问题描述】:

我想如何使我的相对布局中的图像位于我的工具栏上方(在顶层)(在相同的相对布局中)而不是在它下方。任何想法 ? 布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              >

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView2"
        android:src="@drawable/splash"
        android:adjustViewBounds="true"
        android:layout_below="@id/my_toolbar"
        android:gravity="top"
        android:layout_alignTop="@id/my_toolbar"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"/>


    <include
        android:id="@+id/my_toolbar"
        layout="@layout/my_toolbar"
        ></include>

    </RelativeLayout>
</FrameLayout>

工具栏

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
                               android:layout_width="match_parent"
                               android:layout_height="wrap_content"
                               android:minHeight="?attr/actionBarSize"
                               android:theme="@style/ThemeOverlay.AppCompat.Dark"
                               android:background="#7dca2c"
                               android:elevation="4dp"
    >

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

【问题讨论】:

  • 你能发布你的工具栏布局的内容吗

标签: android android-layout android-toolbar android-relativelayout


【解决方案1】:

您不需要RelativeLayout,您的FrameLayout 会处理得很好。

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
         android:layout_width="match_parent"
         android:layout_height="match_parent">

    <include
        android:id="@+id/my_toolbar"
        layout="@layout/my_toolbar"/>

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView2"
        android:src="@drawable/splash"
        android:adjustViewBounds="true"
        android:layout_gravity="top|center_horizontally"/>

</FrameLayout>

通过将包含的布局作为第一个孩子,它将成为第一层 - 而ImageView 将成为第二层。将android:layout_gravity="top|center_horizontally" 添加到ImageView 之后,它将在ViewGroup 中正确对齐。

【讨论】:

  • 我刚试过,不行:(,图片还在我的工具栏下。
  • 它应该可以工作,请告诉我你尝试了什么以及你收到的结果。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-23
  • 2021-11-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-06
相关资源
最近更新 更多