2011-06-03 22 views
0

現在,我的佈局看起來像下面兩張圖片之一,具體取決於屏幕的確切大小。博客,一個,玩遊戲!按鈕位於頂部,另一方面,版權文字位於頂部。如何使用2個值設置layout_Above?

enter image description hereenter image description here

我想要做的就是把AD瀏覽和上面的文本框/佈局的高之間的圖像。根據不同的屏幕尺寸,最上面的條目可能會有所不同。我想不會有這個問題...我知道如何把它放在imageview下面,但不要把它放在兩個項目之上。

到目前爲止,我已經嘗試了一個包含底部變量的relativeLayout,並告訴圖像在上面,但在AdView下面。問題是,儘管將RelativeView的頂部設置爲wrap_content,並且以下任何值都不會很高,但RelativeView的頂部仍會清除頂部。

我也考慮過將文本的頂部對齊到按鈕的頂部,或者反過來,但是我在我的腦海裏看到了一個潛在的醜陋界面,其中頂部按鈕可能更大,或部分版權文字模糊不清。

所以,我正在尋找兩種解決方案之一。一種方式來告訴我的圖像超過2項,按鈕和文本,或者某種方式來包裝上下文,以便我可以在包裝值之上。

這是我測試過的相關XML代碼。

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical"> 
    <com.google.ads.AdView android:id="@+id/adView" ads:loadAdOnCreate="true" ads:adSize="BANNER" ads:adUnitId="@string/admob_unit_id" android:layout_width="wrap_content" android:layout_height="wrap_content" ></com.google.ads.AdView> 
    <ImageView android:src="@drawable/start_logo" android:gravity="center" android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/logo_view" android:layout_below="@+id/adView" android:layout_above="@+id/buttons_copyright"></ImageView> 
    <RelativeLayout android:id="@+id/buttons_copyright" android:layout_width="fill_parent" android:layout_alignParentLeft="true" android:layout_alignParentBottom="true" android:layout_alignParentTop="false" android:layout_height="wrap_content"> 
    (NOTE: LOTS OF STUFF GOES HERE) 
    </RelativeLayout> 
</RelativeLayout> 

回答

4

我做了一個佈局會爲你工作 - 它看起來像這樣: 編輯:試試這個......

enter image description here

使用此佈局(更換頂部按鈕與您的廣告) (改了一下從去年的編輯用花葯相對佈局...)

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <Button 
     android:text="Button" 
     android:id="@+id/button1" 
     android:layout_height="wrap_content" 
     android:layout_width="match_parent"></Button> 
    <TextView 
     android:text="Version Text" 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" 
     android:layout_alignBaseline="@+id/instructions_button" 
     android:layout_toLeftOf="@+id/instructions_button" 
     android:layout_marginLeft="5dp" /> 
    <Button 
     android:id="@+id/instructions_button" 
     android:layout_width="wrap_content" 
     android:text="Instructions" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:minWidth="100dp" 
     android:layout_alignParentBottom="true" /> 
    <TextView 
     android:text="Game Name Text" 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" 
     android:layout_alignBaseline="@+id/scores_button" 
     android:layout_toLeftOf="@+id/scores_button" 
     android:layout_marginLeft="5dp" /> 
    <Button 
     android:id="@+id/scores_button" 
     android:layout_width="wrap_content" 
     android:text="High Scores" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:minWidth="100dp" 
     android:layout_above="@+id/instructions_button" /> 
    <RelativeLayout 
     android:id="@+id/copyright_layout" 
     android:layout_above="@+id/scores_button" 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent"> 
     <TextView 
      android:text="Copyright text goes here and goes on and on a bit and fills up a few lines and looks ok generally and keeps on going and going and going and going onto many lines longer thatn it should etct" 
      android:textSize="10sp" 
      android:layout_height="wrap_content" 
      android:layout_width="fill_parent" 
      android:layout_alignTop="@+id/play_button" 
      android:layout_toLeftOf="@+id/play_button" 
      android:layout_marginLeft="5dp" /> 
     <Button 
      android:id="@+id/play_button" 
      android:layout_width="wrap_content" 
      android:text="Play Game!" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:minWidth="100dp" 
      android:layout_above="@+id/scores_button" /> 
    </RelativeLayout> 
    <ImageView 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" 
     android:id="@+id/imageView1" 
     android:layout_margin="5dp" 
     android:layout_above="@+id/copyright_layout" 
     android:layout_below="@+id/button1" 
     android:src="@drawable/map" 
     android:scaleType="centerCrop" /> 
</RelativeLayout> 
+0

,如果有一個稍微不同的尺寸的屏幕,會發生什麼,版權問題更大?我已經看到這種情況發生在不同大小的模擬器上,因此,這個問題。我試着在自己的代碼中加入類似的代碼,所以... – PearsonArtPhoto 2011-06-03 22:45:03

+0

我已經添加了一些更多的描述來解釋我正在嘗試做什麼,以及爲什麼。底線是,你的版本不適用於我需要支持的每一個尺寸的手機,所以... – PearsonArtPhoto 2011-06-03 22:56:40

+1

它現在應該做的。你可以做的最後一件事就是將這些文本包裝在一個滾動條中,並設置maxLines來表示,5. – 2011-06-03 23:05:08