在Android中支持多个屏幕有问题吗?

在Android中支持多个屏幕有问题吗?,android,Android,海的朋友们,, 我已经开发了一个应用程序,它包含列表视图,并在我的htc设备中发布了.apk文件,设计和对齐都很好,但当我在各种设备(如Morotolo Droid、Nexus设备)中测试时,列表视图的对齐出现了问题,所以我计划使用布局文件夹作为布局hdpi、布局ldpi,和布局mdpi,为此我将清单文件更改为 <supports-screens android:largeScreens="true" android:normalScreens="true" androi

海的朋友们,, 我已经开发了一个应用程序,它包含列表视图,并在我的htc设备中发布了.apk文件,设计和对齐都很好,但当我在各种设备(如Morotolo Droid、Nexus设备)中测试时,列表视图的对齐出现了问题,所以我计划使用布局文件夹作为布局hdpi、布局ldpi,和布局mdpi,为此我将清单文件更改为

<supports-screens android:largeScreens="true" 
        android:normalScreens="true" android:smallScreens="true"
        android:anyDensity="true" /> 

放上android:anyDensity=“true”是否正确?我也使用了dp而不是dip。我浏览了这个网址,但仍然不能得到一个明确的想法在这方面 . 所以朋友们,请告诉我(帮助我)在这件事上有清晰的想法,并告诉我有哪些错误。这是我的主页xml代码frnds

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost" android:layout_width="fill_parent"
    android:layout_height="wrap_content">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/background_retinav2">   

     <LinearLayout android:layout_gravity="center" android:foregroundGravity="bottom" android:background="@color/white" android:id="@+id/rl_1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal">
        <ImageView  android:paddingTop="3dp" android:id="@+id/starthideimage" android:layout_width="30dp" android:layout_height="35dp" android:src="@drawable/newback" />
        <HorizontalScrollView  android:paddingTop="8dp" android:id="@+id/gv"
        android:layout_width="wrap_content" android:layout_marginTop="0dp"
        android:layout_height="wrap_content" android:background="#ffffff"
        android:scrollbars="none" android:layout_weight="1" android:foregroundGravity="bottom">
        <LinearLayout android:id="@+id/san_tag" android:layout_width="wrap_content" android:layout_height="wrap_content">
        </LinearLayout>
    </HorizontalScrollView>
    <ImageView  android:paddingTop="3dp" android:id="@+id/Endhideimage" android:layout_width="30dp" android:layout_height="35dp" android:src="@drawable/newforward" />
    </LinearLayout>

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:id="@android:id/tabcontent"  
        android:layout_width="fill_parent"  android:layout_height="fill_parent">



         <ListView android:id="@+id/content_movies" android:cacheColorHint="@color/cachecolor" 
           android:layout_weight="1" android:scrollbars="vertical"
           android:layout_width="fill_parent" android:layout_height="420dp"/>

        </FrameLayout>   
 </LinearLayout>

<TabWidget
    android:id="@android:id/tabs"
    android:gravity="bottom"
    android:layout_gravity="bottom"
    android:listSelector="@color/gray"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" /> 

</TabHost>

您应该在运行时获得设备的宽度和高度

Display display = getWindowManager().getDefaultDisplay();
screenWidth = display.getWidth();
screenHeight = display.getHeight();
并相应地进行布局

如果您可以用编程方式而不是使用xml来编写布局


这将是最佳实践

是的,Android确实能够更好地使用单独的文件夹名称模式,从而在其中使用用于布局的XML样式表,尽管它使加载时间稍长,而不是使用动态链接的单个XML或直接代码模块,这些模块是从获取屏幕规格的旧Linux方法动态更新的 但是,如果您能够确定您遇到问题的设备是否可能有闪烁屏幕大小报告过程,因为某些设备隐藏了系统触摸按钮和/或带有时钟、WiFi图标、数据网络类型图标的工具栏,etc在某种程度上对许多程序隐藏,例如,1024x600可能报告为1024x552或976x600,因为在antutu使用该方法时,48像素状态栏对获取屏幕高度和宽度命令是隐藏的
因此,在一些继承人系统中,它会看到1024x600,然后实际空间突然变为976x600或1024x552。对于1280x800显示器,这可能是1216x800或1280x736,因为屏幕大小报告中未一致包含64像素状态栏。这只是一个建议,不一定是解决您问题的方法,正如前面有人所说,如果问题不是由于帧格式造成的,那么截图将非常有用,这取决于您的应用程序显示列表数据的方式,即列表数据是带填充参数的直接列表视图还是首先包含在一个方便的框架内

问题可能出现在您的布局中。所以如果你想得到帮助,我建议你把它贴在这里。android:anyDensity=“true”表示您支持所有屏幕分辨率和android 1.6+。如果你有android:anyDensity=“true”,那么拥有android:normalScreens=“true”是没有意义的。@Cement先生:你能再说一遍吗,我已经为你的推荐朋友发布了我的主页xml内容。我有一个dobut,但如果我使用布局高度作为填充父项或换行内容,则listview内容隐藏在Morotolo android设备和Nexus设备中,即y i手动更改高度,并将该值放入布局hdpi、布局ldpi和布局mdpi中。对吗???请告诉我斗士:你还没有说你的问题是什么。如果您只告诉我们“ListView的对齐出错”,我们将无法帮助您。“出错”一词不是很具体。考虑使用DDMS的截图来记录您的问题。另外,如果您的“对齐”是行的内容,那么您需要为我们提供行布局XML,而不是活动布局XML。并且,您可能首先考虑使用<代码>层次结构查看器来确定您的布局规则是否符合预期。这不是Android的最佳实践。如果可能的话,您应该用XML设计布局,以使代码与布局分离。当然,在某些情况下,您必须在运行时更改布局,但在大多数情况下,XML是设置布局的首选方式。因此,您想说,对于不同的设备,我们应该创建大量的XML文件吗?。为什么不为布局创建一个方法并在运行时更改它呢。对于动态工作,您必须在没有XML的情况下工作。这个答案非常不正确。android之所以有不同的文件夹名称功能是有原因的——自动检查屏幕的大小和密度,并相应地放大正确的布局。是的,KCopock试图说,如果需要的话,我们应该为不同的屏幕密度/大小制作尽可能多的xml文件。