繁体   English   中英

如何在另一个视图后膨胀视图

[英]How to inflate a view behind another

如果这是一个简单的问题,请原谅我,但是我是Android开发的新手,这个问题一直困扰着我。

我有一个“基本”布局文件,其中包含此库中的RelativeLayout和com.devspark.sidenavigation.SideNavigationView。

然后,我进行了一个ViewPager活动,该活动将其他布局(包含ListViews和progressBars)扩展到其中。 我的问题是,无论我如何尝试,SideNavigationMenu始终出现在膨胀的列表视图后面。 我不确定发生了什么问题,并且迷失在Layout中。 有人有指针吗?

这是我的“基本”布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".NewNews"
    tools:ignore="MergeRootFrame">  

<com.devspark.sidenavigation.SideNavigationView
    android:id="@+id/side_navigation_view_news"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipChildren="false"/>

</RelativeLayout>

以及一个被夸大的“子”布局之一的示例:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

<eu.erikw.PullToRefreshListView
    android:id="@+id/listView_all"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@android:color/transparent"/>

<ProgressBar
    android:id="@+id/progressBar_all"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center" />

</FrameLayout>

提前致谢

相对布局不支持图层。

视图按照它们添加到布局的顺序彼此放置。

例如

  • 将viewA添加到relativelayout
  • 将viewB添加到relativelayout
  • viewB将在viewA的前面

一种在“后面”膨胀的方法是在另一个视图膨胀之前膨胀另一个视图。

  • 将viewB添加到relativelayout
  • 将viewA添加到relativelayout
  • viewA将在viewB的前面

或删除视图,然后将其重新添加到relativelayout

  • 将viewA添加到relativelayout
  • 将viewB添加到relativelayout
  • 删除viewA
  • 重新添加视图
  • viewA将在viewB的前面

我这样做是这样的:

parentView.addView(childView, 0);

第二个参数是索引,即添加子项的位置

在这里,第二个参数在0处传递,这使得子视图被添加到已经存在的视图的后面。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM