【问题标题】:ImageView should be above everything like the Floating Action ButtonImageView 应该高于浮动操作按钮等所有内容
【发布时间】:2017-04-03 19:23:02
【问题描述】:

我的 MainActivity 中有一个 ImageView,它与浮动操作按钮位于同一位置。 我希望 ImageView 高于浮动操作按钮之类的一切。 目前它看起来像这样: https://gyazo.com/ee0aca8d5bc5061d3e437e6d71575ee8

ImageView 在按钮后面。 但我希望它始终在前台,在应用程序的每个站点上。

我的activity_main.XML:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:orientation="vertical">


    <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:background="@color/orange"
        android:id="@+id/toolbar"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:title="Tanzverbot Soundboard" />

    <android.support.v4.widget.DrawerLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:id="@+id/drawerLayout">

        <RelativeLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/containerView">

            <ImageView
                android:id="@+id/fab"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom|end"
                android:src="@drawable/tanzit"
                android:adjustViewBounds="true"
                android:maxWidth="50dp"
                android:maxHeight="50dp"
                android:layout_above="@+id/adView"
                android:layout_alignParentRight="true"
                android:layout_alignParentEnd="true"
                android:layout_marginRight="32dp"
                android:layout_marginEnd="32dp"
                android:layout_marginBottom="38dp" />

            <com.google.android.gms.ads.AdView
                android:id="@+id/adView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_alignParentBottom="true"
                ads:adSize="SMART_BANNER"
                android:layout_gravity="bottom|end"
                ads:adUnitId="@string/banner_ad_unit_id">
            </com.google.android.gms.ads.AdView>

        </RelativeLayout>



        <android.support.design.widget.NavigationView
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:id="@+id/shitstuff"
            app:itemTextColor="@color/black"
            app:menu="@menu/drawermenu"
            />


    </android.support.v4.widget.DrawerLayout>


</LinearLayout>

【问题讨论】:

    标签: java android android-fragments imageview floating-action-button


    【解决方案1】:

    您应该改用FrameLayout,这样您布局中的最后一个视图将始终位于前台。

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:ads="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        android:orientation="vertical">
    
    
        <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:background="@color/orange"
            android:id="@+id/toolbar"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:title="Tanzverbot Soundboard" />
    
        <android.support.v4.widget.DrawerLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            android:id="@+id/drawerLayout">
    
            <FrameLayout
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/containerView">
    
                <ImageView
                    android:id="@+id/fab"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="bottom|end"
                    android:src="@drawable/tanzit"
                    android:adjustViewBounds="true"
                    android:maxWidth="50dp"
                    android:maxHeight="50dp"
                    android:layout_above="@+id/adView"
                    android:layout_alignParentRight="true"
                    android:layout_alignParentEnd="true"
                    android:layout_marginRight="32dp"
                    android:layout_marginEnd="32dp"
                    android:layout_marginBottom="38dp" />
    
                <com.google.android.gms.ads.AdView
                    android:id="@+id/adView"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerHorizontal="true"
                    android:layout_alignParentBottom="true"
                    ads:adSize="SMART_BANNER"
                    android:layout_gravity="bottom|end"
                    ads:adUnitId="@string/banner_ad_unit_id">
                </com.google.android.gms.ads.AdView>
    
            </FrameLayout>
    
    
    
            <android.support.design.widget.NavigationView
                xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:app="http://schemas.android.com/apk/res-auto"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_gravity="start"
                android:id="@+id/shitstuff"
                app:itemTextColor="@color/black"
                app:menu="@menu/drawermenu"
                />
    
    
        </android.support.v4.widget.DrawerLayout>
    
    
    </LinearLayout>
    

    【讨论】:

    • 他需要LinearLayout 顶部有Toolbar,下面有内容。实际上DrawerLayout 本身扩展了FrameLayout,如果我没记错的话。
    • 我说的是containerView
    • @LuizFernandoSalvaterra 它仍然看起来像这样gyazo.com/9275e291f215d92d5e7f2b8740a3d749
    【解决方案2】:

    尝试交换ImageViewcom.google.android.gms.ads.AdView。 另外,您可以尝试为您的ImageView 设置海拔

    android:elevation="10dp"
    

    【讨论】:

      【解决方案3】:

      试试这个:

      <?xml version="1.0" encoding="utf-8"?>
      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:app="http://schemas.android.com/apk/res-auto"
          xmlns:ads="http://schemas.android.com/apk/res-auto"
          xmlns:tools="http://schemas.android.com/tools"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:fitsSystemWindows="true"
          android:orientation="vertical">
      
          <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:background="@android:color/holo_orange_light"
              android:id="@+id/toolbar"
              android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
              app:title="Tanzverbot Soundboard" />
      
          <android.support.v4.widget.DrawerLayout
              xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:app="http://schemas.android.com/apk/res-auto"
              android:layout_height="match_parent"
              android:layout_width="match_parent"
              android:id="@+id/drawerLayout">
      
              <RelativeLayout
                  android:orientation="vertical"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:id="@+id/containerView">
      
                  <com.google.android.gms.ads.AdView
                      android:id="@+id/adView"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_centerHorizontal="true"
                      android:layout_alignParentBottom="true"
                      ads:adSize="SMART_BANNER"
                      android:layout_gravity="bottom|end"
                      ads:adUnitId="@string/banner_ad_unit_id">
                  </com.google.android.gms.ads.AdView>
      
                  <ImageView
                      android:id="@+id/fab"
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:layout_gravity="bottom|end"
                      android:src="@mipmap/ic_launcher"
                      android:adjustViewBounds="true"
                      android:maxWidth="50dp"
                      android:maxHeight="50dp"
                      android:layout_above="@+id/adView"
                      android:layout_alignParentRight="true"
                      android:layout_alignParentEnd="true"
                      android:layout_marginRight="32dp"
                      android:layout_marginEnd="32dp"
                      android:layout_marginBottom="38dp" />
      
              </RelativeLayout>
      
              <android.support.design.widget.NavigationView
                  xmlns:android="http://schemas.android.com/apk/res/android"
                  xmlns:app="http://schemas.android.com/apk/res-auto"
                  android:layout_width="wrap_content"
                  android:layout_height="match_parent"
                  android:layout_gravity="start"
                  android:id="@+id/shitstuff"
                  app:itemTextColor="@color/black"
                  app:menu="@menu/drawermenu" />
      
          </android.support.v4.widget.DrawerLayout>
      </LinearLayout>
      

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-04
      • 2015-10-31
      • 2018-10-18
      • 2015-09-01
      相关资源
      最近更新 更多