问题
Here is the screenshot from my app:
It's taken from Samsung Galaxy Note
10.1 (mdpi
149 ppi
).
My client thinks that the border line around bottom buttons and rounded rectangle above are blurred.
I'm using shape as a background which looks like this:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
>
<corners
android:radius="8dp" />
<stroke android:width="1dp" android:color="@color/dark_gray" />
<solid android:color="@color/sepia_bright" />
</shape>
When I use simple view as a line with 1dp height like this:
<View
android:background="@color/bright_gray"
android:layout_width="match_parent"
android:layout_height="1dp" />
It's perfectly sharp as you can see on next screenshot:
Simple horizontal lines are ok, but rectangle around graph is blurred again.
What am I doing wrong?
Thanks for any help.
回答1:
My first guess would be that this is a problem with bi-linear filtration (http://en.wikipedia.org/wiki/Bilinear_filtering).
To fix it, see The View#setLayerType method.
I had an issue with this in a custom view. Inside my view's init method, I have the following code:
if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB){
this.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
This fixed my issue, but you could do the same thing using the android:layerType
xml attribute, or the setLayerType
method in code on your view.
来源:https://stackoverflow.com/questions/22641772/blurred-1dip-shape-lines-borders-on-android