2011-11-29 128 views
0

我使用了relativelayout,這裏是我得到的。我無法獲得圖像來填充我想要的部分。我不知道如何解決它。我聽說過有關使用佈局權重的一些問題,我應該使用哪些內容?XML佈局重疊文本問題

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
android:background="@drawable/background"> 


<ImageView 
    android:id="@+id/imagehome" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_marginLeft="10dp" 
    android:layout_marginRight="10dp" 
    android:layout_margin="10dp" 
    android:layout_alignParentTop="true" 
    android:layout_centerHorizontal="true" 
    android:layout_above="@+id/tvtitle1" 
    android:src="@drawable/one" /> 

    <TextView 
     android:id="@+id/tvtitle1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"   
     android:gravity="center_vertical" 
     android:text="Voted Best Dentist five years running by" 
     android:textSize="16dp" 
     android:textColor="#9D4F1B" 
     android:layout_above="@+id/tvtitle2" 
     android:layout_centerHorizontal="true" 
     android:layout_marginBottom="6dp"/> 


    <TextView 
     android:id="@+id/tvtitle2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:gravity="center_vertical" 
     android:text="The Oakland Tribune" 
     android:textSize="16dp" 
     android:textColor="#9D4F1B" 
     android:layout_above="@+id/tvhome" 
     android:layout_centerHorizontal="true" 
     android:layout_marginBottom="15dp"/> 

    <TextView 
     android:id="@+id/tvhome" 
     android:layout_width="280dp" 
     android:layout_height="wrap_content" 
     android:gravity="center_vertical" 
     android:text="  You&apos;ll be cared for by our highly trained staff of dental professionals,energized to work as a team while providing the highest quality of care for your dental health. We offer complete dentistry for the entire family at a single location.               " 
     android:textColor="#4C2016" 
     android:textSize="15dp" 
     android:layout_centerHorizontal="true" 
     android:layout_above="@+id/special" 
     android:layout_marginBottom="25dp" /> 


    <Button 
     android:id="@+id/special" 
     android:layout_width="120dp" 
     android:layout_height="40dp" 
     android:background="@drawable/cc" 
     android:text="Specials" 
     android:textColor="#F6E6C6" 
     android:textSize="17dp" 
     android:textStyle="bold" 
     android:layout_centerHorizontal="true" 
     android:layout_above="@+id/tvbutton" 
     android:layout_marginBottom="15dp" /> 


    <TextView 
     android:id="@+id/tvbutton" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="App provided by Bay Area Dental Marketing" 
     android:layout_centerHorizontal="true" 
     android:textSize="10dp" 
     android:layout_alignParentBottom="true" /> 



</RelativeLayout> 
對XML文件

enter image description here

和設備

enter image description here

它得到了更好,但it'snot尚未有對!

+0

我剛編輯我已經得到考慮的建議 – Mona

回答

1

在使用多種屏幕尺寸時,我發現最佳做法是(a)使用RelativeLayout或(b)在ScrollView內設置LinearLayout

+0

@Mona,'RelativeLayout'可讓您根據屏幕上的其他項目指定項目的位置。如果你正在使用'Eclipse',開始輸入屬性'android:',然後等待它加載一個可能的屬性列表。如果你輸入'align',你會得到你想要使用的屬性列表。 – Phil

+0

我要試試這個,並讓你知道謝謝 – Mona

+0

我剛剛編輯我的問題 – Mona

1

使用RelativeLayout,因此您不必指定像素。

如果您正在爲某個特定手機做這件事,請在Eclipse中的XML設計器中選擇相應的屏幕大小。然而,使用RelativeLayout保證它可以在所有電話上工作

+0

我不確定如何使用relativelayout。我只是用relativelayout替換線性佈局嗎?或者我也必須更改頁面中的項目的一些東西。如果你能解釋更多,我會很高興。謝謝 – Mona

+0

我不能像解釋「Pro Android」和其他許多書籍一樣好解釋,並在Google網站和許多互聯網資源中解釋。 –

2

不知道你有多少靈活性,但最好的解決方案是從背景中刪除文本和圖像,並將它們添加爲視圖。正如你所經歷的,除非每件作品被添加爲視圖,否則幾乎不可能保證它在所有設備上看起來都是正確的。

1

即使使用上面的建議答案,您仍可能遇到不同大小屏幕上的問題。我能想到的最佳解決方案是爲背景和前景創建單獨的圖像資源,然後添加一個以前景圖像爲源的圖像視圖。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    android:background="@drawable/background" > 
<!-- This method makes this layout redundant, dont need this anymore 
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginLeft="23dip" 
    android:layout_marginRight="15dip" 
    android:layout_marginTop="255dip" 
    android:orientation="vertical" >--> 


<!-- put the foreground image in an imageview --> 
<ImageView android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:src="@drawable/foregroundImage"/> 


<TextView 
    android:layout_width="276dp" 
    android:layout_height="132dp" 
    android:textSize="15dp" 
    android:gravity="center_vertical" 
    android:text="some text" 
    android:textColor="#4C2016"/> 

<Button 
    android:id="@+id/special" 
    android:layout_width="131dp" 
    android:layout_height="40dp" 
    android:background="@drawable/cc" 
    android:layout_marginTop="20dip" 
    android:layout_marginLeft="75dip" 
    android:textSize="17dp" 
    android:textStyle="bold" 
    android:text="Specials" 
    android:textColor="#F6E6C6" /> 
</LinearLayout>