如何编程确定应用程序当前使用的布局(普通布局、大型布局等)?我看到getWindowManager().getDefaultDisplay().getMetrics(metrics)调用,但它似乎只处理屏幕密度,而不需要应用程序使用的布局。我需要这些信息,因为我需要在运行时动态地编程更改视图的某些位置。
提前谢谢。

最佳答案

要做到这一点,一个非常简单的方法是为父布局设置一个id和标记,在onCreate()中,您可以findViewById()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
}

07-24 09:45
查看更多