2010-05-28 3 views
80

내 ListView에 선형 그래디언트를 적용하려고합니다.안드로이드 : 배경으로 선형 그래디언트를 사용하여 줄무늬가 보이는

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <gradient 
     android:startColor="#3A3C39" 
     android:endColor="#181818" 
     android:angle="270" 
    /> 
    <corners android:radius="0dp" /> 
</shape> 

그래서 나는 내 ListView에에 적용 : 이 내 당김 XML의 내용입니다

android:background="@drawable/shape_background_grey" 

그것은 작동하지만 에뮬레이터에서 너무 실제 장치에 매우 "줄무늬"보인다 .

"동작"을 줄일 수있는 방법이 있습니까?

+3

스크린 샷을 게시 할 수 있습니까? – CommonsWare

+18

그냥 업데이트 : getWindow(). setFormat (PixelFormat.RGBA_8888); \t \t getWindow(). addFlags (WindowManager.LayoutParams.FLAG_DITHER); onCreate 메서드는 화면을 음소거하는 hdpi (N1/Desire) –

+2

@ @ Francesco' Great!그것은 ** 안드로이드 2.2 **와 함께 ** 갤럭시 S **에 도움이되었습니다. 유용한 의견을 답변으로 변환하여 사람들이 투표 할 수 있도록하십시오. –

답변

79

는 로맹 가이 알 수 있듯이 :

listView.getBackground().setDither(true); 

내 문제

해결이 특히 AMOLED 및/또는 hdpi에 장치는이 시도에 대해 충분하지 않은 경우에

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

안드로이드 1.6 이상에서는 작동하지 않습니다. 내 다른 코멘트보기 –

+8

XML에서 이것을 할 수 있습니까? –

+7

"작동하지 않음"또는 "현재 작동 중"입니까? 거기에는 큰 차이가 있습니다. –

38

Drawable 개체에서 간단하게 디더링을 사용할 수 있습니다.

+1

예, 작동합니다! 타이. BTW이 속성을 드로어 블 XML 정의에 사용하려고했지만 문서가 더 잘 읽혀 지므로이 속성은 선택기 요소에 대해서만 지원됩니다. –

+0

안타깝게도 Android 버전 1.5 이상에서는 작동하지 않습니다. Android 1.6 및 Android 1.5가 설치된 실제 기기에서 테스트했습니다. 드로어 그라디언트에 디더를 추가하면 효과가 없습니다. 장치는 모두 320 x 480 (180 ppi)입니다. 어떠한 제안? Tnx –

+1

'setDither()'는 API 레벨 23에서 사용되지 않습니다. 이제이 속성은 무시됩니다. –

8

이 넣어 당신의 활동 :

@Override 
public void onAttachedToWindow() { 
    super.onAttachedToWindow(); 
    Window window = getWindow(); 
    window.setFormat(PixelFormat.RGBA_8888); 
} 
3
useLevel이 = "true"로 기울기에 : HTC 디자 이어에 나를 위해

내가 안드로이드를 설정할 때 밴딩이 사라 나를 위해이

window.getDecorView().getBackground().setDither(true); 
+0

'setDither()'는 API 레벨 23에서 더 이상 사용되지 않습니다.이 속성은 이제 무시됩니다. –

1

처럼 작동 gradient_dark.xml

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"> 
    <gradient android:startColor="#464646" 
     android:endColor="#323232" 
     android:angle="270" 
     android:type="linear" 
     android:useLevel="true" 
     /> 
</shape> 

하지만 먼저 I 밴딩을 제거하기 위해 "노이즈"드로어 블이있는 레이어 목록을 사용하여 시도했지만 도움이되었지만 여전히 밴딩이 있습니다.

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" > 
    <item android:drawable="@drawable/gradient_dark"/> 
    <item> 
     <bitmap 
      android:gravity="center" 
      android:src="@drawable/noise_repeater" 
      android:tileMode="repeat" /> 
    </item> 

</layer-list> 

은 "noise_repeater"당김은 내가 만든

enter image description here

0

나를 때문에 StartColor 및 endColor 모두 약간 투명 알파 채널을 설정하는 것이었다 근무 유일한 방법을 사용했다.

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <gradient 
     android:startColor="#FE3A3C39" 
     android:endColor="#FE181818" 
     android:angle="270" 
    /> 
</shape> 

내가이 다른 SO 질문에서 이것을 시도 할 수있는 아이디어를 가지고 : android:dither=“true” does not dither, what's wrong?

1

디더 및 RGBA_888 설정이 일부 휴대 전화에 도움이되지 않는 경우를,이 솔루션은 요소를 layerTypesoftware에를 설정할 수 있습니다 하드웨어 가속을

비활성화
android:layerType="software" 

이 는 삼성 S5 전화에 내 문제를 해결했습니다.

+0

나에게 문제가 수정되었습니다 - 감사합니다! –