Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/189.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android平板电脑编程存在简单但严重的问题_Android_Xml_Android Layout - Fatal编程技术网

android平板电脑编程存在简单但严重的问题

android平板电脑编程存在简单但严重的问题,android,xml,android-layout,Android,Xml,Android Layout,因此,我正在学习谷歌的“开发Android应用程序”课程,我陷入了困境,因为我遇到了一个无法解释的严重问题: 请看,他们的想法是在文件夹res\layout-sw600dp下为平板电脑创建一个不同的布局文件,这样,如果设备的最小高度/宽度为600dips,则会有不同的布局。 唯一的问题是,出于某种原因,断言不起作用,无论是对于他们的代码还是我在这里添加的简单代码,至少对于AVD平板电脑(我使用了Nexus10和API21)。 例如,以下代码在烤面包片上显示“Phone!”而不是“Tablet!”

因此,我正在学习谷歌的“开发Android应用程序”课程,我陷入了困境,因为我遇到了一个无法解释的严重问题:

请看,他们的想法是在文件夹res\layout-sw600dp下为平板电脑创建一个不同的布局文件,这样,如果设备的最小高度/宽度为600dips,则会有不同的布局。 唯一的问题是,出于某种原因,断言不起作用,无论是对于他们的代码还是我在这里添加的简单代码,至少对于AVD平板电脑(我使用了Nexus10和API21)。 例如,以下代码在烤面包片上显示“Phone!”而不是“Tablet!”:

当layout-sw600dp文件夹下的xml文件确实有一个id为weather\u detail\u container的框架时

我将添加我在电子邮件底部创建的两个xml文件,但您也可以尝试以下Google项目中的branch 5.10-它不会加载应有的两个窗格: ,至少不适用于任何AVD设备(我有一部物理android手机,但没有物理平板电脑)

要完成此问题,这里有两个xml文件:

在文件夹布局下,这是activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">


        <TextView
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:text="Whatever"/>

      </LinearLayout>
<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.
    -->

    <TextView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="2"
       android:text="Whatever" />

    <FrameLayout
        android:id="@+id/weather_detail_container"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="4" />

</LinearLayout>

在layout-sw600dp文件夹下,这是activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">


        <TextView
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:text="Whatever"/>

      </LinearLayout>
<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.
    -->

    <TextView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="2"
       android:text="Whatever" />

    <FrameLayout
        android:id="@+id/weather_detail_container"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="4" />

</LinearLayout>

您需要询问/获取
屏幕布局\u大小\u掩码
,这是关键。。。 我只在三星设备上试过,但非常准确

例子:
您需要询问/获取
屏幕布局\u大小\u掩码
,这是关键。。。 我只在三星设备上试过,但非常准确

例子:
好了,伙计们,我对我的问题有了一个可行的答案: 只需在emulator设置中取消选中“启用设备框架”! 如果您需要进一步帮助,可以使用此链接:


说了这么多,我不知道为什么会这样。毕竟,该设置的定义是:“在Android emulator窗口周围启用一个模仿真实Android设备外观的框架”,因此根据我的理解,应该只改变外观。所以,如果有人知道原因,请发表进一步的回答或评论:)

好的,伙计们,我刚刚得到了一个可行的答案来回答我的问题: 只需在emulator设置中取消选中“启用设备框架”! 如果您需要进一步帮助,可以使用此链接:


说了这么多,我不知道为什么会这样。毕竟,该设置的定义是:“在Android emulator窗口周围启用一个模仿真实Android设备外观的框架”,因此根据我的理解,应该只改变外观。因此,如果有人知道原因,请发表进一步的回答或评论:)

可能重复的可能重复的感谢,但这仍然无助于膨胀正确的布局文件(如果我必须在运行时膨胀所有视图,而不是使用xml,那么这将打破代码和我想要使用的对象之间的解耦,对吗?)…最重要的是,在getResources()下,您可以获得手机的宽度和高度,并将其与常数600进行比较-这将是一种更好的手动方式,而这不是我想要的!!谢谢,但这仍然无助于膨胀正确的布局文件(如果我必须在运行时膨胀所有视图,而不是使用xml,那么这将打破代码和我想要使用的对象之间的脱钩,对吗?)。除此之外,在getResources()下,您可以获得手机的宽度和高度,将其与常数600进行比较-这将是一种更好的手动方式,而这不是我想要的!!