2012-01-17 3 views
0

바둑판 식 이미지를 프로그램 배경으로 추가하려고합니다.XMLView에 ImageView를 추가하면 프로그램이 예기치 않게 멈 춥니 다.

충돌되어 나는 현재 main.xml에에서 사용하고 코드 :

<?xml version="1.0" encoding="utf-8"?> 
<ImageView xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:src="@drawable/cartoonclouds" 
android:contentDescription="@string/desc" > 
<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/hello" /> 
</LinearLayout> 
</ImageView> 

을하지만, ImageView이 제거되고 xmlnsLinearLayout로 이동 될 때, 그것은의없이 (고급 기능 코스, 이미지).

LogCat에서 관련 오류를 볼 수 없습니다.

더 많은 정보 :

이클립스와 안드로이드 2.2, API (8) 프로그램이 실행하지만, 사용 즉시 충돌합니다.

답변

0

ImageView에는 아무 것도 넣을 수 없습니다. 그것은 레이아웃이 아닙니다. LinearLayoutbackground 속성을 사용하여 이미지의 배경을 설정하십시오.

또 다른 옵션은 모든 것을 RelativeLayout으로 마무리하는 것입니다. ImageViewLinearLayout을 분리하십시오. 이미지는 RelativeLayout으로 채우고 LinearLayout이 그 위에 표시됩니다.

예 :

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <ImageView 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:src="@drawable/cartoonclouds" 
    android:contentDescription="@string/desc" /> 
    <LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 
    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="@string/hello" /> 
    </LinearLayout> 
</RelativeLayout> 
+0

완벽하게 일을했다. 그러나 이미지를 어떻게 타일링 할 수 있습니까? –

+0

나는 그것을 모른다. 나는 한번도 시도한 적이 없다. 'ImageView'를 사용하면 이미지의 크기를 조절할뿐입니다. 'background' 속성은 같은 것을합니다. 가능하다면 나는 궁금해서 다른 질문을 할 수도 있습니다. – DeeV

+0

http://stackoverflow.com/questions/8899222/tiling-images-in-android-with-imageview-in-xml –

0

이미지 뷰 내부에 선형 레이아웃을 추가하지 마십시오. 상단에 직선으로 선을 긋고 거기에 이미지 뷰를 추가하십시오.

관련 문제