25

私は次のコードを持っています:

   <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"/>

2つの質問があります:

  1. なぜ線が白ではなく黒なのですか?ImageView内に配置してみましたが、結果は同じです。
  2. シェイプの不透明度を設定するにはどうすればよいですか?
4

3 に答える 3

28

android:color1) 線の色を設定するには、 で定義する必要があります<stroke>。この<solid>要素は背景用です。

2) アルファ レイヤー、別名 #ARGBで色の値を使用して、形状の不透明度を設定できます。あなたの場合、おそらく #7FFF です。

于 2010-05-03T14:11:42.810 に答える
21

黒色の 2 密度ピクセルの線の最も単純な例。xml をドローアブル フォルダーに保存するだけです: res/drawable/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 と background を使用して線を表示します。

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

これが役に立ったことを願っています。

于 2014-09-02T05:14:15.997 に答える