2011-10-24 23 views
0

我正在開發一個Android應用程序(請參閱屏幕截圖)。Android視圖被剪輯到某個點以下

我有一個在圖形編輯器中看起來很好的佈局。然而,當應用程序在模擬器以及android手機中運行時,屏幕的底部1/4會被剪切掉。該應用程序有幾個活動,這個問題似乎對所有人都是普遍的。

The view from my eclipse editor The view from my android emulator

下面是我使用的佈局。

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout android:layout_width="fill_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android" android:clipChildren="false" android:clipToPadding="false" android:layout_height="fill_parent"> 
    <ImageView android:layout_height="wrap_content" android:src="@drawable/simpsonstextblack" android:layout_width="fill_parent" android:id="@+id/TitleImage" android:paddingBottom="25dp"></ImageView> 
    <RelativeLayout android:layout_below="@+id/TitleImage" android:layout_height="wrap_content" android:layout_width="fill_parent" android:id="@+id/RelativeLayout1" android:padding="5dp"> 
     <Button android:text="Take the Simpsons Challenge" android:gravity="center" android:clickable="true" android:id="@+id/ChallengeButton" android:layout_width="fill_parent" android:textSize="20dp" android:background="@drawable/buttonbackgroundblue" android:layout_height="50dp"></Button> 
     <TextView android:layout_width="fill_parent" android:layout_below="@+id/ChallengeButton" android:layout_alignLeft="@+id/ChallengeButton" android:id="@+id/spacer1" android:layout_height="6dp"></TextView> 
     <Button android:layout_width="fill_parent" android:text="Free Play" android:clickable="true" android:id="@+id/FreePlayButton" android:layout_height="50dp" android:textSize="20dp" android:background="@drawable/buttonbackgroundblue" android:layout_below="@+id/spacer1"></Button> 
     <TextView android:layout_width="fill_parent" android:id="@+id/spacer2" android:layout_below="@+id/FreePlayButton" android:layout_alignLeft="@+id/FreePlayButton" android:layout_height="6dp"></TextView> 
     <Button android:layout_height="50dp" android:textSize="20dp" android:id="@+id/HighScoreButton" android:background="@drawable/buttonbackgroundblue" android:layout_width="fill_parent" android:text="High Scores" android:layout_below="@+id/spacer2"></Button> 
     <TextView android:layout_width="fill_parent" android:id="@+id/spacer3" android:layout_below="@+id/HighScoreButton" android:layout_alignLeft="@+id/HighScoreButton" android:layout_height="6dp"></TextView> 
     <Button android:layout_height="50dp" android:textSize="20dp" android:id="@+id/HelpButton" android:background="@drawable/buttonbackgroundblue" android:layout_width="fill_parent" android:text="Help" android:layout_below="@+id/spacer3"></Button> 
    </RelativeLayout> 
    <RelativeLayout android:layout_below="@+id/RelativeLayout1" android:layout_width="fill_parent" android:id="@+id/RelativeLayout2" android:clipChildren="false" android:clipToPadding="false" android:layout_height="fill_parent"> 
     <TextView android:id="@+id/spacer1" android:layout_width="fill_parent" android:layout_height="30dp"></TextView> 
     <TextView android:layout_below="@+id/spacer1" android:layout_height="wrap_content" android:layout_width="fill_parent" android:textAppearance="?android:attr/textAppearanceMedium" android:id="@+id/QuoteText" android:text='"A woman is a lot like a refrigerator. Six feet tall, 300 pounds…it makes ice. Heres some extra filler text just to demonstrate to you that if you add enough text it will most likely get clipped at some random point in the screen seemingly for no reason."'></TextView> 
    </RelativeLayout> 
</RelativeLayout> 
+0

我無法在我的設備上重現此問題。當你在你的設備上運行時,它會顯示與模擬器相同的東西嗎? – Craigy

+0

是的,屏幕截圖取自模擬器本身。嘗試在底部textview中添加更多行文本,看看它們是否被剪輯。 – Allen

+0

我在說的是它可以在物理設備上正常工作,而不是在仿真器中,但它應該在仿真器中工作。只是想排除這種可能性。我添加了足夠的文本行來滾動屏幕底部,但它只是將其剪輯在設備屏幕的邊緣。 – Craigy

回答

2

我的猜測是你的應用程序在兼容模式下運行。嘗試設置在清單如下:

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

如果你可以閱讀更多關於它這裏的問題:http://developer.android.com/guide/topics/manifest/supports-screens-element.html。 總之android:largeScreens的默認值各不相同accros版本:)

1

問題是你最後的TextView(@+id/QuoteText)設置爲android:visibility="invisible"。這意味着內容不可見,但仍佔用空間。你想用android:visibility="gone"來代替。

我很抱歉說它在我的手機上無法正常工作。由於文本沒有到達設備屏幕的底部,因此我在頂部的ImageView中添加了空間,但是這會將TextView屏蔽掉屏幕上的文本,所以它似乎適用於我。希望這可以幫助!

編輯:

這也不是問題。我相信問題是你的底部RelativeLayout被定義爲

<RelativeLayout 
    android:layout_width="fill_parent" 
    android:id="@+id/RelativeLayout1" 
    android:layout_height="200dp"> 

它給底部面板一個固定的高度。當我將android:layout_height="200dp"更改爲android:layout_height="fill_parent"時,削波問題對我而言將消失。也許你和其他活動有同樣的問題?

我不明白爲什麼你的佈局不起作用,但我確實認爲你可以通過使用LinearLayouts而不是RelativeLayouts來更容易和更高效地實現相同的功能。也許它會一路解決你的問題。而不是使用你的spacer視圖,我認爲最好使用填充。這就是我的意思:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <ImageView 
     android:id="@+id/TitleImage" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:scaleType="fitStart" 
     android:src="@drawable/simpsonstextblack" > 
    </ImageView> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/TitleImage" 
     android:orientation="vertical" 
     android:padding="5dp" > 

     <Button 
      android:id="@+id/ChallengeButton" 
      android:layout_width="fill_parent" 
      android:layout_height="50dp" 
      android:clickable="true" 
      android:paddingLeft="6dp" 
      android:paddingRight="6dp" 
      android:text="Take the Simpsons Challenge" 
      android:textSize="20dp" > 
     </Button> 

     <Button 
      android:id="@+id/FreePlayButton" 
      android:layout_width="fill_parent" 
      android:layout_height="50dp" 
      android:clickable="true" 
      android:paddingLeft="6dp" 
      android:paddingRight="6dp" 
      android:text="Free Play" 
      android:textSize="20dp" > 
     </Button> 

     <Button 
      android:id="@+id/HighScoreButton" 
      android:layout_width="fill_parent" 
      android:layout_height="50dp" 
      android:paddingLeft="6dp" 
      android:paddingRight="6dp" 
      android:text="High Scores" 
      android:textSize="20dp" > 
     </Button> 

     <Button 
      android:id="@+id/HelpButton" 
      android:layout_width="fill_parent" 
      android:layout_height="50dp" 
      android:paddingLeft="6dp" 
      android:paddingRight="6dp" 
      android:text="Help" 
      android:textSize="20dp" > 
     </Button> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical" > 

     <TextView 
      android:id="@+id/QuoteText" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:paddingTop="30dp" 
      android:text="&quot;A woman is a lot like a refrigerator. Six feet tall, 300 pounds…it makes ice. Heres some extra filler text just to demonstrate to you that if you add enough text it will most likely get clipped at some random point in the screen seemingly for no reason. &quot;" 
      android:textAppearance="?android:attr/textAppearanceMedium" /> 
    </LinearLayout> 
</LinearLayout> 
+0

我知道那個textview是不可見的。我應該把它解決掉,但這不是問題(如果我將它設置爲不存在,屏幕仍然會在屏幕上下剪75%,並遮住報價文本。同樣,這個問題在應用程序中的所有活動中都很普遍,所以問題可能不在於任何單獨的視圖元素 – Allen

+0

你是對的,那不是問題我已經編輯了我的答案,看看它是否有幫助 – Craigy

+0

沒有效果,仍然被剪裁 – Allen