2010-05-03 1 views
16

나는이 다음 코드 :안드로이드 모양의 라인

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="line"> 
    <stroke android:width="1dp"/> 
    <size android:height="1dp" /> 
    <solid android:color="#FFF"/> 
    </shape> 


    <LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background ="@drawable/line"/> 

나는 두 가지 질문이있다 : 라인 대신 흑백 왜

  1. ? ImageView 내부에 넣으려고했지만 그 결과는 같습니다.
  2. 어떻게 모양의 불투명도를 설정할 수 있습니까?

답변

21

1) 줄의 색을 설정하려면 <stroke>android:color을 정의해야합니다. <solid> 요소는 배경입니다.

2) color values with an alpha layer, 별명 #ARGB를 사용하여 도형의 불투명도를 설정할 수 있습니다. 어쩌면 # 7FFF.

+0

# 07FFFFFF를 의미합니다. – Vaiden

+0

@Vaiden Android는 4 자리 ARGB를 지원합니다. 이 경우 # 77FFFFFF로 해석됩니다. –

8

검은 색을 띤 2 개의 밀도 픽셀에 대한 가장 간단한 예입니다. 그냥 당김 폴더에 XML을 저장 : 고해상도/드로어 블/사진 shape_black_line.xml

<?xml version="1.0" encoding="utf-8"?> 
<shape 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:shape="line"> 
<stroke 
    android:width="1dp" 
    android:color="#000000" /> 
<size android:height="2dp" /> 
</shape> 

사용의 LinearLayout과 배경 라인을 표시합니다.

<LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:background="@drawable/divider"> 
</LinearLayout> 

이 도움이 되었기를 바랍니다.

+3

LinearLayout 대신에 ''을 사용하면 메모리를 덜 소비하지 않을까요? –

+0

네, 사용할 수 있습니다. 모든 클래스가보기에서 확장되므로 –