【发布时间】:2025-11-22 18:45:02
【问题描述】:
我正在开发一个玩具应用程序,它具有不同的手机和平板电脑布局文件,但在平板电脑模式下,它没有使用 layout-sw600dp 文件夹中的正确布局。这是我的文件内容:
activity_main.xml 在layout-sw600dp 文件夹中:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:divider="?android:attr/dividerHorizontal"
android:orientation="horizontal"
tools:context="com.example.android.sunshine.app.MainActivity">
<!--
This layout is a two-pane layout for the Items master/detail flow.
-->
<fragment
android:id="@+id/fragment_forecast"
android:name="com.example.android.sunshine.app.ForecastFragment"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
tools:layout="@android:layout/list_content" />
<FrameLayout
android:id="@+id/weather_detail_container"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="4" />
</LinearLayout>
activity_main.xml 在layout 文件夹中:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/fragment_forecast"
android:name="com.example.android.sunshine.app.ForecastFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
tools:context="com.example.android.sunshine.app.ForecastFragment"
tools:layout="@android:layout/list_content" />
MainActivity.java 中的onCreate 方法:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mLocation = Utility.getPreferredLocation(this);
setContentView(R.layout.activity_main);
if(findViewById(R.id.weather_detail_container) != null)
{
mTwoPane = true;
if(savedInstanceState == null)
{
getSupportFragmentManager().beginTransaction().replace(R.id.weather_detail_container, new DetailActivityFragment(),DETAILFRAGMENT_TAG).commit();
}
}
else
{
mTwoPane = false;
}
}
我正在使用emulated Nexus 10 来测试应用程序。当应用程序出现时,它会显示单窗格布局,与手机视图相同。我不知道这里出了什么问题。
我也尝试了emulated Nexus 7,但问题仍然存在。
令人惊讶的是,我尝试使用 Samsung Galaxy Note 10.1 API 16 real device 并且布局完美。导致问题的仿真设备是否存在任何问题?
编辑
我怀疑模拟设备有问题并尝试emulate Samsung Galaxy Note 10.1 API 16。布局也适用于设备的模拟版本。
我也尝试将API 16 与emulated Nexus 7 一起使用,但我仍然得到了单窗格布局。 Nexus 7 & 10 和 layout-sw600dp 文件夹有问题吗?
【问题讨论】:
-
你试过sw720dp吗?
-
Nexus 10 使用 layout-sw720dp 文件夹。 Here 更多详情。
-
@gj_ 是的,我试过了,同样的问题
-
@VladimirJovanović 顾名思义,它是最小的宽度,并且由于 nexus 10 属于该类别,它应该显示它。无论如何,我尝试使用 sw720 并没有运气