2012-09-11 9 views
2

![當前佈局] http://i50.tinypic.com/qqznzs.png如何使用位圖作爲Android中的背景從LinearLayout中刪除黑條?

我想從佈局的頂部和底部得到blakc酒吧,而不是黑色的白色。我已經嘗試改變背景顏色了。

抽拉CODE:

<?xml version="1.0" encoding="utf-8"?> 
<bitmap xmlns:android="http://schemas.android.com/apk/res/android" 
    android:gravity="clip_horizontal|clip_vertical|center" 
    android:src="@drawable/theblindgoat_logo" 
    android:tileMode="disabled" > 
</bitmap> 

主代碼:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/startup" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="#FFFFFF" 
    android:orientation="vertical" > 

順便說一句我需要的圖像不是垂直伸展,從而改變這不是一個需要解決辦法。

+0

可以發佈整個xml佈局嗎? – ChristopheCVB

+0

我現在做了。它並不是在最初的main中設置爲drawable,而是設置在activity中,所以它只會在動畫發生後才生效。 – jrquick

回答

2

那些黑條只是主題背景的顏色。爲了擺脫它們,你可以將你的位圖繪製爲白色背景色的圖層列表,如下所示:

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" > 

    <item> 
     <color android:color="@android:color/white"/> 
    </item> 

    <item> 
     <bitmap android:gravity="clip_horizontal|clip_vertical|center" 
      android:src="@drawable/theblindgoat_logo" 
      android:tileMode="disabled" /> 
    </item> 

</layer-list> 
1

你能夠擺脫那個黑色兩種方式:您LinearLayout

  • 設定背景爲白色的顏色,然後用所需的圖像源

或者

添加 ImageView
  • android:theme="@android:style/Theme.Light.NoTitleBar"設置爲您在 的活動AndroidManifest.xml中,剩下的,因爲它是
+0

感謝您的幫助,但不會涉及太多細節,我無法將圖像視圖添加到我的線性佈局中,搞亂了其他佈局項目,底層解決方案似乎無法解決它。 – jrquick

+0

然後簡單地與我的第二個選項,即爲您的活動設置一個輕的主題 – waqaslam

+0

這就是我所說的,第二個解決方案似乎沒有改變任何東西。 – jrquick

0

嘗試的LinearLayout的背景設置爲位圖,例如:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/startup" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/theblindgoat_logo" 
    android:orientation="vertical" > 

這應該舒展你的形象來填充背景。

+0

我想我應該已經更具體,但我需要圖像留下沒有拉伸。感謝您的幫助。 – jrquick