【问题标题】:How to get current layout on android? [closed]如何在android上获取当前布局? [关闭]
【发布时间】:2017-04-04 09:36:06
【问题描述】:

我的应用总是不同的布局

A.xmlB.xmlC.xml

我想在当前布局AB 执行disconnect() 方法时。

那么,如何在 android 上获取当前布局?

【问题讨论】:

  • 问题不清楚

标签: android android-layout


【解决方案1】:

试试这些:

View currentView = this.getWindow().getDecorView().findViewById(android.R.id.content)

View currentView = this.findViewById(android.R.id.content)

View currentView = this.findViewById(android.R.id.content).getRootView()

如果你给你的布局文件的每个根标签加上一个id,你可以得到视图,如下所示:

<RelativeLayout
    android:id="@+id/rl_root_one"

然后获取视图:

RelativeLayout relativeLayout = (RelativeLayout)findViewById(R.id.rl_root_one);

使用上述任何一种方法,您都可以得到当前视图的膨胀。

【讨论】:

    【解决方案2】:

    你可以用这个

    this.getWindow().getDecorView().findViewById(android.R.id.content)
    

    或者这个

    this.findViewById(android.R.id.content).getRootView()
    

    【讨论】:

      猜你喜欢
      • 2014-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-30
      • 1970-01-01
      • 2012-05-09
      相关资源
      最近更新 更多