2011-08-31 2 views
14
여기

는 내가하고 싶은 것입니다Android : XML 드로어 블을 스케일링 할 수 있습니까? 나는이 규모의 XML이 :

<?xml version="1.0" encoding="utf-8"?> 
<scale xmlns:android="http://schemas.android.com/apk/res/android" 
    android:drawable="@drawable/mydrawable" 
    android:scaleGravity="bottom" 
    android:scaleHeight="50%" /> 

을 그리고 나는이 당김 XML을 사용하려면 : 다음

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item> 
     <shape xmlns:android="http://schemas.android.com/apk/res/android" 
      android:shape="rectangle"> 
      <gradient android:startColor="#FFFFFFFF" 
       android:endColor="#FFFF0000" 
       android:angle="90" /> 
     </shape> 
    </item> 
</layer-list> 

내가 배경으로 스케일 XML 설정 LinearLayout에 대해서는,하지만 아무것도 보이지 않습니다. 내가 누락되었거나 XML로이 작업을 수행 할 수 없습니까?

+1

BTW 최상위 요소는 레이어 목록을 둘러 쌀 필요없이 '모양'이 될 수 있습니다. 또한 어떤 리소스 디렉토리에 이러한 파일이 있습니까? – Greyson

+0

죄송합니다. 방금 늦게까지이 사실을 알게되었습니다. – Greyson

+0

@michelemarcon : 끝내 주셨어요? – Behnam

답변

3

이것은 XML로 해결할 수없는 ScaleDrawable 개체의 문제입니다.

// Get the scale drawable from your resources 
ScaleDrawable scaleDraw = (ScaleDrawable)getResources().getDrawable(R.drawable.background_scale); 
// set the Level to 1 (or anything higher than 0) 
scaleDraw.setLevel(1); 

// Now assign the drawable where you need it 
layout.setBackgroundDrawable(scaleDraw); 

나는이 솔루션을 사용하여 코드를 테스트하고 그것을 잘 작동 :

하지만 쉽게, 그냥 다음을 수행합니다.

관련 문제