2011-08-03 24 views
0

こんにちは図形があり、レイアウトにこれを含めるようにしていますが、表示されません。Androidにxml形式の図形が含まれています

これは私の形状のxml「damage.xml」

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
shape="rectangle"> 
<solid color="#ff0000" /> 
<stroke width="3dp" color="#ff0000" /> 

であり、これは私の私は、レイアウト形状を含めるために必要と考えられています。

<?xml version="1.0" encoding="utf-8"?> 

<View android:id="@+id/damage" android:background="@layout/damage" 
    android:layout_width="5dip" android:layout_height="wrap_content"> 
</View> 

<ImageView android:id="@+id/icon" android:layout_width="60px" 
    android:layout_height="60px" android:layout_marginRight="6dip" 
    android:src="@drawable/placeholder" /> 

<LinearLayout android:orientation="vertical" 
    android:layout_width="wrap_content" android:layout_height="wrap_content" 
    android:padding="6dip"> 

    <TextView android:layout_width="fill_parent" android:id="@+id/title" 
     android:layout_height="wrap_content" android:text="Item Name" 
     android:textStyle="bold" android:singleLine="true" android:textSize="16sp" /> 

    <ImageView android:id="@+id/rating" android:layout_width="wrap_content" 
     android:layout_height="wrap_content" android:src="@drawable/rating_five" /> 


    <LinearLayout android:orientation="horizontal" 
     android:layout_width="wrap_content" android:layout_height="wrap_content"> 

     <TextView android:layout_width="wrap_content" android:id="@+id/range" 
      android:layout_height="wrap_content" android:text="Range" 
      android:textStyle="bold" android:singleLine="true" android:textSize="16sp" 
      android:paddingRight="5dip" /> 

     <TextView android:layout_width="fill_parent" android:id="@+id/condition" 
      android:layout_height="wrap_content" android:text="Condition" 
      android:textStyle="bold" android:singleLine="true" android:textSize="16sp" /> 

    </LinearLayout> 
</LinearLayout> 

しかし何も描かれていませんか?どこが間違っているのですか?次に、ビュー内の図形の幅と高さを設定するのが正しいか、またはdamage.xmlでそれを実行する必要がありますか?例えば

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
shape="rectangle"> 
<solid color="#ff0000" /> 
<size android:height="wrap_content" /> 
<size android:width="5dip" /> 
<stroke width="3dp" color="#ff0000" /> 

ここでは、コンパイラはwrap_content文句を言います。

ご協力いただければ幸いです。

答えて

1

color="#ff0000"android:color="#ff0000"に変更してみてください。これにより、矩形が表示されるはずです。これを行うと、赤い四角形が表示されますが、親ビューは垂直に塗りつぶされます。これは、長方形に固定された高さがないのに、android:layout_height="wrap_content"を使用したためです。レイアウトでandroid:layout_heightの値を使用して修正します。

また、damage.xmlをレイアウトディレクトリに配置したようです。シェイプはドロウアブルなので、ドロウアブルディレクトリに配置してレイアウト内に@layout/damageという名前を付ける必要があります。

更新:

damage.xmlに次のコードを使用するには、矩形が私のために罰金を表示させます。

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"> 
    <solid android:color="#f0f000" /> 
    <stroke android:width="3dp" android:color="#ff0000" /> 
</shape> 
+0

android:color = ""は動作していないようです。また、damage.xmlをドロウアブルフォルダに移動しました。長方形がリスト行の高さ全体を占めるようにしたいので、wrap_contentを選択したのです。他にどんな価値がありますか? – Bear

+0

長方形がリスト行の高さ全体を占めるようにするには、おそらくlayout_height = "match_parent"を使用するべきです。 –

+0

素晴らしい作品:-)多くのありがとう – Bear

関連する問題