Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/312.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
Java 故障-不同密度下的相同布局_Java_Android_Android Layout_Android Emulator - Fatal编程技术网

Java 故障-不同密度下的相同布局

Java 故障-不同密度下的相同布局,java,android,android-layout,android-emulator,Java,Android,Android Layout,Android Emulator,我正在用HVGA和WVGA800测试我的应用程序,两者的分辨率都是普通屏幕,所以我创建了中密度和高密度的图像,但我不明白为什么我在HVGA中的文本“Orientação”(标题)与WVGA800相比是分散的,我用“dp”单位编码如下: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

我正在用HVGA和WVGA800测试我的应用程序,两者的分辨率都是普通屏幕,所以我创建了中密度和高密度的图像,但我不明白为什么我在HVGA中的文本“Orientação”(标题)与WVGA800相比是分散的,我用“dp”单位编码如下:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
    <ImageView
        android:id="@+id/imageCanadaNavBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:adjustViewBounds="true"
        android:src="@drawable/canada_navbar"
        android:onClick="imgTop_Click"  />       
   <ImageView 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_below="@id/imageCanadaNavBar"
        android:src="@drawable/bg_viagem"
        android:scaleType="fitXY" />                                
    <TextView 
        android:id="@+id/txtTitle"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"            
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:layout_marginTop="30dp"             
        android:textColor="#000000"
        android:textSize="19sp"
        android:gravity="center|center_vertical"        
        android:layout_below="@id/imageCanadaNavBar" />    
    <ScrollView 
        android:id="@+id/scrollTextoDetalhe"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_marginTop="20dp"
        android:layout_marginBottom="7dp" 
        android:layout_below="@id/txtTitle">                       
        <TextView 
            android:id="@+id/txtDetalhe"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"                       
            android:textColor="#FFFFFF"
            android:textSize="15dp"
            android:paddingRight="25dp"
            android:paddingLeft="25dp"
            android:paddingBottom="17dp"
            android:paddingTop="17dp" />        
    </ScrollView>
</RelativeLayout>

尝试使用
sp(缩放独立像素)
而不是
dp(牙本质独立像素)

建议将其用于文本大小单位


您的边距和填充设置使它在一个实例中看起来居中,即使它实际上不是


将android:gravity=“center”更改为
android:gravity=“center | center_vertical”
,您的问题应该得到解决(您可能需要调整一点边距和填充)。

我建议您将文本视图的背景设置为背景,而不是使用单独的图像视图。您还应该确保Drawable是一个9面片,以便可以正确缩放和调整填充/边距。因此,不是:

<ImageView 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_below="@id/imageCanadaNavBar"
    android:src="@drawable/bg_viagem"
    android:scaleType="fitXY" />                                
<TextView 
    android:id="@+id/txtTitle"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"            
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:layout_marginTop="30dp"             
    android:textColor="#000000"
    android:textSize="19sp"
    android:gravity="center|center_vertical"        
    android:layout_below="@id/imageCanadaNavBar" />

您应该有如下内容:

<TextView 
    android:id="@+id/txtTitle"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"            
    android:padding="10dp"
    android:textColor="#000000"
    android:textSize="19sp"
    android:gravity="center|center_vertical"       
    android:background="@drawable/bg_viagem" 
    android:layout_below="@id/imageCanadaNavBar" />

在我的例子中,我将所有图像分离,以生成一个唯一的XML图像

这是我的最后一个应用程序

我尝试了sp而不是dp,但效果相同。我快疯了!我测试了你的提示,但是HVGA设备上的布局仍然错误。你删除了上边距了吗?我相信定心是在边缘之后进行的,所以有一个顶部边缘但没有底部边缘的人会将所有东西向下移动。不在家,所以我不能重复检查,但我相信是这样的。你也可以发布周围的布局代码吗?(家长和兄弟姐妹视图)@kabuko当然,我在上面添加了完整的xml布局。