2

For some reason I can't get the background of my navbar to render smoothly. What am I doing wrong here? Here is my main activity xml file:

<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>

Here's the navigation bar that it loads:

<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>

Here's the gradient drawable:

<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>

Finally, here's the activity:

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;
}


}
LoneWolfPR
  • 3,978
  • 12
  • 48
  • 84
  • Well, I installed it to my phone, and the banding is gone. It only seems to be in the emulator. The only other difference is the emulator is running 4.2 simulating a Galaxy Nexus. My phone is an old Droid Incredible (1st generation) running Gingerbread. I'm getting a Galaxy S4 soon. I'll just have to see if the problem persists on that phone. – LoneWolfPR May 23 '13 at 13:48

1 Answers1

0

There are more options you can try : antialiasing and filtering.

Enable them by creating a bitmap from an xml file that points to your bitmap like this :

<?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>

Edit: it appears that bitmap xml won't load xml drawable in such way ...

I don't see anything except maybe this solution from romain guy :

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

seen on this post : Android: Using linear gradient as background looks banded

Did you try it ?

Community
  • 1
  • 1
Guian
  • 4,563
  • 4
  • 34
  • 54
  • Doesn't this require a bitmap image instead of the gradient shape I'm using? – LoneWolfPR May 23 '13 at 13:07
  • The documentation only says : "Reference to a drawable resource". I guess you will have to define dimensions ( with left, top, right, bottom attributes) cause it will probably need its intrinsic bounds to be set... :/ let us know if you try it. – Guian May 23 '13 at 13:18