如何确定哪个XML布局我的Android应用程序的使用? [英] How to programatically determine which XML layout my Android apps is using?
问题描述
我如何确定哪个布局(布局正常,布局大等),我的应用程序正在使用?我看到getWindowManager()。getDefaultDisplay()。getMetrics(指标)的调用,但它似乎只处理的屏幕密度,但没有必要,这样的布局应用程序使用。我需要的信息,因为我需要在运行时动态编程来改变一些看法的定位。
How do I programatically determine which layout (layout-normal, layout-large, etc.) my app is currently using? I see the getWindowManager().getDefaultDisplay().getMetrics(metrics) call but it seems to only deal with screen density but not necessary which layout the app is using. I need the info since I need to programatically change some of the positioning of views dynamically at runtime.
在此先感谢。
推荐答案
这是非常简单的方法来做到这一点,是由ID和标签设置到父布局,并在你的的onCreate()
,您可以 findViewById()
和 getTag()
。
An extremely easy way to do this, is by setting a id and tag to the parent layout and in your onCreate()
, you can findViewById()
and getTag()
.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/my_activity_view"
android:tag="big_screen" >
// misc views~
</RelativeLayout>
然后,在你的的onCreate
方法
if(findViewById(R.id.my_activity_view).getTag().equals("big_screen")) {
// do stuff
}
这篇关于如何确定哪个XML布局我的Android应用程序的使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!