2013-05-16 44 views
2

出於某種原因,我無法讓我的導航欄的背景渲染流暢。我在這裏做錯了什麼?這是我的主要活動的xml文件:Android:綁定導航欄的漸變背景。 setDither不工作

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context=".MainActivity" > 

<ImageView 
    android:id="@+id/HomeBackground" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:contentDescription="@string/homescreen_desc" 
    android:src="@drawable/homescreen" 
    android:scaleType="centerCrop" 
    /> 
<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_above="@+id/NavigationBar"></RelativeLayout> 
<include 
    android:layout_gravity="bottom" 
    layout="@layout/navigation_main" /> 

</RelativeLayout> 

下面是它加載的導航欄:

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/NavigationBar" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:orientation="vertical" 
android:layout_alignParentBottom="true" 
android:padding="5dp" 
android:background="@drawable/gradient_bar_bg"> 
<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center_horizontal"> 

    <ImageButton 
     android:id="@+id/home_button" 
     android:contentDescription="@string/home_btn_txt" 
     android:layout_width="40dp" 
     android:layout_height="40dp" 
     android:src="@drawable/home" 
     android:scaleType="centerInside" 
     android:tint="#176fe6" 
     android:layout_marginLeft="15dp" 
     android:layout_marginRight="15dp" 
     android:background="@android:color/transparent"/> 

    <ImageButton 
     android:id="@+id/explore_button" 
     android:contentDescription="@string/explore_btn_txt" 
     android:layout_width="40dp" 
     android:layout_height="40dp" 
     android:src="@drawable/compass1" 
     android:scaleType="centerInside" 
     android:tint="#176fe6" 
     android:layout_marginLeft="15dp" 
     android:layout_marginRight="15dp" 
     android:background="@android:color/transparent"/> 

    <ImageButton 
     android:id="@+id/info_button" 
     android:contentDescription="@string/info_btn_txt" 
     android:layout_width="40dp" 
     android:layout_height="40dp" 
     android:src="@drawable/info2" 
     android:scaleType="centerInside" 
     android:tint="#176fe6" 
     android:layout_marginLeft="15dp" 
     android:layout_marginRight="15dp" 
     android:background="@android:color/transparent"/> 

    <ImageButton 
     android:id="@+id/social_button" 
     android:contentDescription="@string/social_btn_txt" 
     android:layout_width="40dp" 
     android:layout_height="40dp" 
     android:src="@drawable/chat" 
     android:scaleType="centerInside" 
     android:tint="#176fe6" 
     android:layout_marginLeft="15dp" 
     android:layout_marginRight="15dp" 
     android:background="@android:color/transparent"/> 
</LinearLayout> 
</LinearLayout> 

這裏的梯度繪製:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
<item> 
    <shape android:shape="rectangle"> 
     <solid android:color="#004097" /> 
    </shape> 
</item> 
<item android:top="2dp"> 
    <shape> 
     <gradient 
      android:angle="90" 
      android:startColor="#FF004097" 
      android:endColor="#FF0153ca" 
      android:type="linear" /> 
    </shape> 
</item> 
</layer-list> 

最後,這裏的活動:

package org.childrensmuseum.visittcmindy; 

import android.app.Activity; 
import android.os.Bundle; 
import android.view.Menu; 

public class MainActivity extends Activity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    getWindow().setFormat(PixelFormat.RGBA_8888); 
    findViewById(R.id.NavigationBar).getBackground().setDither(true); 
} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.activity_main, menu); 
    return true; 
} 


} 
+0

好吧,我把它安裝到了我的手機上,綁定消失了。它似乎只在模擬器中。唯一的區別是仿真器運行4.2模擬Galaxy Nexus。我的手機是運行薑餅的舊Droid Incredible(第一代)。我很快就會得到Galaxy S4。我只需要看看問題是否仍然存在於該手機上。 – LoneWolfPR

回答

0

The您可以嘗試更多選項:抗鋸齒和過濾。

<?xml version="1.0" encoding="utf-8"?> 
<bitmap 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:src="@drawable/your_drawable_id" 
    android:antialias="true" 
    android:dither="true" //I think this is the same one you already tried 
    android:filter="true" 
</bitmap> 

編輯:

由指向您的位圖這樣的一個XML文件中創建一個位圖啓用他們看來,在這種方式的位圖XML將不會加載XML繪製...

我沒有看到任何東西,除了從羅曼蓋伊也許這個解決方案:

@Override 
public void onAttachedToWindow() { 
    super.onAttachedToWindow(); 
    Window window = getWindow(); 
    window.setFormat(PixelFormat.RGBA_8888); 
} 

上看到這個帖子:Android: Using linear gradient as background looks banded

你試過了嗎?

+0

這不需要位圖圖像而不是我正在使用的漸變形狀? – LoneWolfPR

+0

該文檔只說:「引用可繪製資源」。我想你將不得不定義維度(左邊,頂部,右邊,底部屬性),因爲它可能需要設置其內在界限......:/讓我們知道你是否嘗試過。 – Guian

+0

剛剛嘗試過。導致模擬器崩潰。不過謝謝。 – LoneWolfPR