【问题标题】:Android show one layout element over anotherAndroid 在另一个布局元素上显示一个布局元素
【发布时间】:2016-02-17 09:11:07
【问题描述】:

我知道这类问题已经在这里讨论过很多次了。但就我而言,他们都没有为我工作。我在带有导航抽屉的项目中使用AndroidSlidingUpPanel。问题是滑动面板布局总是显示在导航抽屉上,但我想要的是相反的。这是目前的情况

如您所见,我看不到导航抽屉项目。滑动面板布局隐藏了导航抽屉。

这是我的代码

<?xml version="1.0" encoding="utf-8"?>

<com.sothree.slidinguppanel.SlidingUpPanelLayout xmlns:sothree="http://schemas.android.com/apk/res-auto"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/sliding_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="bottom"
    sothree:umanoDragView="@+id/dragView"
    sothree:umanoOverlay="false"
    sothree:umanoPanelHeight="68dp"
    sothree:umanoParalaxOffset="100dp"
    sothree:umanoShadowHeight="4dp">


    <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/drawerMainActivity"
        android:layout_width="match_parent"
        android:layout_alignParentBottom="true"
        android:layout_height="match_parent">



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

            <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="?android:attr/actionBarSize"
                android:background="?attr/colorPrimary"
                android:id="@+id/toolBar"
                android:fitsSystemWindows="true"
                android:theme="@style/ThemeOverlay.AppCompat.Dark"
                />

        </FrameLayout>


        <android.support.v7.widget.RecyclerView
            android:layout_width="240dp"
            android:layout_height="match_parent"
            android:id="@+id/recyclerView"
            android:scrollbars="vertical"
            android:background="#FFFFFF"
            android:layout_gravity="left"
            />

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


    <!-- SLIDING LAYOUT -->
    <LinearLayout
        android:id="@+id/dragView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#ffffff"
        android:clickable="true"
        android:focusable="false"

        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/name"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:textColor="@android:color/holo_green_dark"
                android:gravity="center_vertical"
                android:paddingLeft="10dp"
                android:text="@string/slide"
                android:textSize="14sp" />

            <Button
                android:id="@+id/btn_hide"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:gravity="center_vertical|right"
                android:paddingLeft="10dp"
                android:paddingRight="10dp"
                android:text="@string/hide"
                android:textSize="14sp" />

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#FFCCCC">

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="10dp"
                android:layout_weight="1"
                android:scaleType="centerCrop"
                android:src="@drawable/image" />
        </LinearLayout>
    </LinearLayout>


</com.sothree.slidinguppanel.SlidingUpPanelLayout>

我该如何解决这个问题?所以导航抽屉总是在滑动面板布局之上。

【问题讨论】:

  • 您是否尝试过将DrawerLayout 设置为根元素?
  • @PPartisan 谢谢,它现在正在工作。
  • @PPartisan 你能发表你的评论作为答案吗?

标签: android android-layout navigation-drawer slidingpanelayout


【解决方案1】:

将您的 DrawerLayout 设置为根元素,而不是您的 SlidingUpPanelLayout

【讨论】:

    【解决方案2】:

    要设置 Z 轴,您必须订购树。来自文档

    View.html#Drawing

    这棵树大部分是按顺序记录和绘制的,绘制的是父母 在他们的孩子之前(即之后),按顺序绘制兄弟姐妹 它们出现在树中。如果您为视图设置背景可绘制对象, 然后视图将在回调其 onDraw() 方法之前绘制它。 子绘图顺序可以被自定义子绘图覆盖 在 ViewGroup 中排序,并设置 setZ(float) custom Z values} 观看次数。

    所以基本上把 Drawerlayout 设置为最后一个。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-21
      相关资源
      最近更新 更多