簡體   English   中英

麻煩-不同密度的相同布局

[英]Trouble - Same Layout in Different Densities

我正在測試以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>

WVGA800和HVGA之間的比較

嘗試使用sp (Scale-independent Pixels)而不是dp (Dentisy-Independent Pixels)

建議將其用於文本大小單位。

http://developer.android.com/guide/topics/resources/more-resources.html#Dimension

您的邊距和填充設置使它在一個實例中居中,即使實際上並非如此。

android:gravity="center"更改為android:gravity="center|center_vertical" ,您的問題應得到解決(您可能需要調整邊距並稍微填充一下)。

我建議您不要將單獨的ImageView用作TextView的背景,而是將其實際設置為背景。 您還應該確保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格式的唯一圖像。

新版面

這是我最后的應用程序Canada Destino

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM