2012-01-17 10 views
0

プログラムの背景としてタイル画像を追加しようとしています。ImageViewをXMLファイルに追加すると、プログラムが予期せず停止する

私は現在、クラッシュされ、main.xmlに使用していますコード:ImageViewが削除され、xmlnsLinearLayoutに移動したときに

<?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> 

しかし、それは、のなし(細かい機能コース、画像)。

LogCatに関連するエラーはありません。

詳細情報:

のEclipseとAndroid 2.2、API 8.プログラムの実行が、を使用するには、即座にクラッシュします。

答えて

0

ImageViewには何も配置できません。それはレイアウトではありません。 LinearLayoutbackground属性を使用して、画像の背景を設定します。

もう1つの方法は、すべてを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

イメージビュー内に線形レイアウトを追加しないでください。一番上にルートとして直線レイアウトをしてそこに画像ビューを追加する

関連する問題