2012-11-16 48 views
1

因此,我試圖將相機預覽作爲背景進行查看,並在其上面顯示圖像視圖。檢查我所問過的這個question out,以更好地瞭解我想要完成的工作。然而,我沒有使用FrameLayout,而是發現使用RelativeLayout更容易(因爲在屏幕上放置視圖的原因)。問題是我無法獲取imageview(通過表面視圖)佔據整個屏幕。無論我如何重新調整圖像大小,它仍然顯示在中央而不會填滿屏幕。RelativeLayout中的ImageView與父項不匹配

所以,我的問題是,我將如何使imageview充滿整個屏幕的表面視圖?也許,我犯了一個簡單的錯誤,但如果是這種情況,請指出。任何幫助將不勝感激!謝謝!

下面是XML文件:

<?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" 
android:id="@+id/relative" > 

<ImageView 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:id="@+id/image" 
    android:src="@drawable/background" > 
</ImageView> 

<Button 
    android:id="@+id/scan" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerHorizontal="true" 
    android:layout_centerVertical="true" 
    android:layout_margin="10dp" 
    android:text="Scan" 
    android:textSize="20dp" 
    android:textStyle="bold" 
    android:onClick="Scan" /> 

<Button 
    android:id="@+id/search" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/scan" 
    android:layout_centerHorizontal="true" 
    android:layout_margin="10dp" 
    android:text="Search" 
    android:textSize="20dp" 
    android:textStyle="bold" 
    android:onClick="Search" /> 

<Button 
    android:id="@+id/importing" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/search" 
    android:layout_centerHorizontal="true" 
    android:layout_margin="10dp" 
    android:text="Import" 
    android:textSize="20dp" 
    android:textStyle="bold" 
    android:onClick="Import" /> 

</RelativeLayout> 

這裏的地方,我把意見代碼(帶至前面,所以他們在表面視圖中可見):

mPreview = new CameraPreview(this, mCamera); 
    relative.addView(mPreview); 
    layout.bringToFront(); 
    scan.bringToFront(); 
    search.bringToFront(); 
    friendImport.bringToFront(); 

編輯: 下面是我正在談論的一個示例圖像(我試圖讓白色透明圖像覆蓋整個屏幕):

image not displaying full screen

回答

0

經過一段時間的實驗後,我似乎找到了解決我的問題的方法。我的圖像顯示一個類似這樣的畫面:

9 patch description

這是奇怪的,因爲這是怎樣一個9補丁圖像的作品,我沒有宣佈我的圖像作爲9補丁。但即使當我調用match_parent(或甚至fill_parent)它只填充到填充區域,就像我張貼的圖像。

因此,有了大量的試驗和錯誤,我拿走了圖像上的任何邊界,並取消了所有的模糊效果。出於某種原因,該圖像的文件尺寸明顯較小。然後,我嘗試將此作爲背景並...成功!

我不太確定它爲什麼不起作用,但是,我有一個理論,可能是因爲圖像上有一個1px的邊框,它將它保存爲9個修補程序的PNG的正常PNG文件。或者可能是由於圖像上的模糊效果。我不太確定,但是,我確實知道,一旦我消除了模糊效果並刪除了邊框,它確實有效。

我希望這對任何可能遇到類似問題的人都有用!

1

我正確的想要將android:id =「@ + id/image」擴展到整個佈局中嗎? 首先在佈局視圖中檢查ImageView佔用整個空間的程度。 如果是這樣,那麼適當的比例類型添加到您的ImageView的屬性列表:

android:scaleType="fitXY" 

或者作爲替代,應用圖像資源不作爲「SRC」,但作爲「背景」:

android:background="@drawable/background" 

祝你好運。

+0

是的,這是正確的,我想機器人:ID =「@ + ID /圖像」是整個屏幕大小。不幸的是,我已經嘗試了你所說的兩種方法,但沒有運氣。我還使用「fill_parent」屬性來表示高度和寬度,但這似乎什麼都不做。如果您有任何其他建議可以隨意說明,我就會迷失在這裏 – chRyNaN

相關問題