Android 支持不同的屏幕大小-xml加载不正确。可能的错误?

Android 支持不同的屏幕大小-xml加载不正确。可能的错误?,android,xml,eclipse,android-layout,layout,Android,Xml,Eclipse,Android Layout,Layout,结尾的问题 我有以下文件夹和文件(略去不重要的): 布局/活动\u map.xml: <?xml version="1.0" encoding="utf-8"?> <fragment xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:map="http://schemas.android.c

结尾的问题

我有以下文件夹和文件(略去不重要的):

布局/活动\u map.xml

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.MapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MapActivity" />
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:minHeight="48dp"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin" >

    <TextView
        android:id="@+id/place_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:duplicateParentState="true"
        android:fontFamily="sans-serif-light"
        android:text="@android:string/unknownName"
        android:textColor="@color/missions_item_text"
        android:textSize="18sp" />

</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:baselineAligned="false" 
    tools:context=".MapActivity" >

    <ListView
        android:id="@+id/map_places_list"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:divider="@color/missions_divider"
        android:dividerHeight="1dp"
        android:listSelector="@drawable/missions_listselector"
        tools:ignore="InconsistentLayout"
        tools:listitem="@layout/list_item_place_map" />

    <fragment
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.MapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<resources>

    <dimen name="activity_horizontal_margin">16dp</dimen>
    <dimen name="activity_vertical_margin">16dp</dimen>
    <dimen name="main_sign_in_textsize">14sp</dimen>
    <dimen name="main_greeting_textsize">18sp</dimen>
    <dimen name="main_missions_textsize">18sp</dimen>
    <dimen name="main_progress_textsize">40sp</dimen>

</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>

    <dimen name="main_greeting_textsize">20sp</dimen>

</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>

    <dimen name="activity_horizontal_margin">128dp</dimen>

</resources>
activity\u map
在所有3个文件夹上都相同,但右侧的颜色除外

正如您在屏幕截图(取自Eclipse布局预览)中所看到的,该列表未正确显示以下项目:

  • 10.1英寸(使用sw600dp版本)
  • Nexus 10(使用sw720dp版本)
我在模拟器上测试了这个项目,得到了相同的结果

编辑2

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.MapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MapActivity" />
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:minHeight="48dp"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin" >

    <TextView
        android:id="@+id/place_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:duplicateParentState="true"
        android:fontFamily="sans-serif-light"
        android:text="@android:string/unknownName"
        android:textColor="@color/missions_item_text"
        android:textSize="18sp" />

</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:baselineAligned="false" 
    tools:context=".MapActivity" >

    <ListView
        android:id="@+id/map_places_list"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:divider="@color/missions_divider"
        android:dividerHeight="1dp"
        android:listSelector="@drawable/missions_listselector"
        tools:ignore="InconsistentLayout"
        tools:listitem="@layout/list_item_place_map" />

    <fragment
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.MapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<resources>

    <dimen name="activity_horizontal_margin">16dp</dimen>
    <dimen name="activity_vertical_margin">16dp</dimen>
    <dimen name="main_sign_in_textsize">14sp</dimen>
    <dimen name="main_greeting_textsize">18sp</dimen>
    <dimen name="main_missions_textsize">18sp</dimen>
    <dimen name="main_progress_textsize">40sp</dimen>

</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>

    <dimen name="main_greeting_textsize">20sp</dimen>

</resources>
<?xml version="1.0" encoding="utf-8"?>
<resources>

    <dimen name="activity_horizontal_margin">128dp</dimen>

</resources>
我上传了一个小项目,在github上重现了我的问题:

根据@anddev84的建议,我使用了HierarchyViewer。到目前为止,我发现列表中的所有
place\u name
textview都被正确加载。但是,RelativeLayout容器无法正确显示。我还没有弄清楚在运行时RelativeLayout或TextView的属性中是否存在问题,或者是否有其他东西造成冲突(可能是错误?)。

我看到一个打字错误(可能)?这些应该是一样的吗

 tools:listitem="@layout/list_item_place_map"
但文件名是:

list_item_places_map.xml
“地点地图”!-“地点和地图”

编辑 作为对您使用错误文件夹编辑Eclipse的回应,我在值和可绘制文件中也发现了同样的问题。有时Eclipse和AVD使用不同的文件夹,但都弄错了(比如Galaxy S4)。其他时候,至少AVD是正确的

我最近问了两个问题。其中一个给了我风滚草徽章


我还看到Eclipse(设置为显示AVD)与特定设备和API的AVD呈现布局的方式有很大的不同。使用我们提供的开发工具似乎只是一个废话,只有在真正的设备上进行测试,您才能真正验证内容的外观。

我认为问题在于您没有为相关设备的资源目录树指定“精确匹配”。这都是在开发页面上详细说明的

根据开发页面,设备最好选择屏幕密度可用的最近资源。在您最初的问题(不是颜色示例)中,您提供了一个
'layout-sw600dp-land
,但没有
values-sw600dp-land
,因此设备将找到与您提供的景观和其他限定符匹配的第一组值,以及最接近的屏幕密度


尝试为所有配置添加
文件夹(所有所需的屏幕密度、纵向和
陆地
),看看这是否能为您解决问题。

您的
列表视图
的硬宽度为200度,但您已经将其项目的左/右填充定义为屏幕宽度为720个或更多的设备中的128个凹陷,这样就没有空间容纳实际内容。您将需要更改
sw720dp焊盘的列表项尺寸,或者将宽度增加到256度以上(填充当前占用的空间),或者将填充减少到100度以下(这将占用整个区域)。

是的,我的错。但这是我的问题,不是我的项目。修正了这个想法,但是如果它找不到那个文件夹,它应该返回到默认的文件夹
(包含所有内容)是的,你是正确的。您是否尝试过在HierarchyViewer中查看您的文本视图是否显示?您可以确定这是因为边距值的问题还是其他问题。我并没有使用HierarchyViewer,因为我并没有运行Android系统开发者版本的设备。我将在模拟器上试一试。我还上传了我的小项目,它在GitHub
https://github.com/gian1200/TestProblem
您不需要开发人员版本。Romain Guy发布了这个ViewServer项目,您可以在自己的应用程序中包含并使用它来启用HierarchyViewer。看这里:非常感谢你花时间。这是一个小小的错误,你无法想象我有多感激。事实上,这种额外的填充是我问题的根源。我会尽快给你奖金。@gian1200:很高兴我能帮忙:)希望你的应用程序玩得开心!