【问题标题】:DecorView Child FrameLayoutDecorView 子框架布局
【发布时间】:2012-07-26 18:10:46
【问题描述】:

有人可以向我解释为什么我的布局上的 DecorView 的子级是 FrameLayout 而我还没有定义一个?

这里是xml布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/background_general" >

<ImageView
    android:id="@+id/ivIKUGo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:src="@drawable/mainbutton_selector" />

<ImageView
    android:id="@+id/imageViewmoto"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_marginBottom="150dp"
    android:src="@drawable/motto_buttonpage_hdpi" />

</RelativeLayout>

谢谢

【问题讨论】:

  • 这就是 android 中构建活动的方式,除了你的内容之外,活动还可以显示其他元素,例如操作栏。活动的内容通过id android.R.id.content 添加到FrameLayout
  • @Luksprog 好的,我有另一个示例项目,DevorView 的子项目是 LinearLayout,这个项目有什么不同吗?
  • 我不记得确切的DecorView 是如何构建的,但是您使用setContentView 设置的布局已添加到ID 为android.R.id.contentFrameLayout。您对DecorView 感兴趣有什么特别的原因吗?
  • 感谢您的回复我正在尝试实现github.com/bk138/LibSlideMenu,其中也有一个示例,当您运行示例时,如果您检查 hiearchyviewer,您会看到 decorview 在内容框架布局之前有一个线性布局子级。
  • 我已经运行了这些项目,但没有发现任何问题。有一个 DecorView 和一个 LinearLayout 和一个子 FrameLayout(android.R.id.content),还有活动的内容视图。

标签: android android-layout


【解决方案1】:

如果您使用普通主题,您将在DecorViewFrameLayout 之间有一个LinearLayout,其中包含Activity 的内容。如果您使用NoTitleBar 类型的主题,则不需要额外的LinearLayout,因此将其删除,将内容FrameLayout 作为DecorView 的子项。

【讨论】: