2016-05-12 4 views
0

xmlを使って以下のような形状にする必要があります。xmlを使ってAndroidでdrawableshapeを作成するには?

enter image description here

私は、XMLコードの下に使用して楕円形を作成しました。

<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
    <!-- This is the line --> 

    <item android:height="400dp"><shape 
     android:shape="oval"> 

     <solid android:color="#000000" /> 

    </shape></item> 

</layer-list> 

しかし、私は一緒に直線と円を描くことができないのです。 xmlを使って上記の形にするのを助けてください。

+3

xml用のものではなく、 – pskink

答えて

0

にサークル形状を作成するためのコードです。

は、手順に従っ: -

1.Createdドットまたは塗りつぶされた円を描画する描画可能なフォルダにdot.xmlと呼ばれるXMLファイルを。

//Dot.xml 
<?xml version="1.0" encoding="utf-8"?> 
    <shape xmlns:android="http://schemas.android.com/apk/res/android" 
     android:shape="oval" > 
    <solid android:color="@color/colorTimeline" /> 
    </shape> 

2.以下のコードをレイアウトファイルに挿入します。

<View 
     android:id="@+id/v1" 
     android:layout_width="1dp" 
     android:layout_height="50dp" 
     android:background="@color/colorTimeline" 
     android:contentDescription="ad" 
     android:layout_marginStart="10dp"/> 

    <View 
     android:id="@+id/v2" 
     android:layout_width="16dp" 
     android:layout_height="16dp" 
     android:background="@drawable/dot" 
     android:contentDescription="f" 
     android:layout_marginStart="3dp" 
     android:layout_below="@id/v1" 
     android:layout_marginEnd="24dp"/> 
    <View 
     android:id="@+id/v3" 
     android:layout_width="1dp" 
     android:layout_height="50dp" 
     android:background="@color/colorTimeline" 
     android:contentDescription="ad" 
     android:layout_marginStart="10dp" 
     android:layout_below="@id/v2"/> 

最終出力: - 私はあなたのソリューションを見ると

Output Screenshot

0
<?xml version="1.0" encoding="utf-8"?> 
    <shape xmlns:android="http://schemas.android.com/apk/res/android" 
      android:shape="oval"> 
      <solid android:color="@color/comment_background"/> 
      <stroke android:color="@color/gray" android:width="0.5dp"/> 
    </shape> 

これは最後に、私は少しグーグル後の溶液が付属しているアンドロイド

0

私の目は、出血、申し訳ありません。私はあなたにこれを作り、見せなければなりませんでした。この例は、既知のサイズのビューに対してのみ機能します。動的な値を使用したい場合は、プログラマチックに私のサンプルドロアブルを作成してください。

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" > 
    <!-- VERTICAL LINE --> 
    <item 
     android:left="9dp" 
     android:right="9dp"> 
     <shape 
      android:shape="rectangle"> 
      <solid 
       android:color="#FF0000" /> 
      <size 
       android:width="2dp" 
       android:height="200dp" /> 
     </shape> 
    </item> 

    <!-- OVAL --> 
    <item 
     android:top="90dp" 
     android:bottom="90dp"> 

     <shape 
      android:shape="oval"> 
      <solid 
       android:color="#FF0000" /> 
      <size 
       android:width="20dp" 
       android:height="20dp" /> 
     </shape> 
    </item> 
</layer-list> 

私に知らせてください。

+0

用の9個のパッチドローラブルを使用してください。 – pskink

+0

@pskinkはい、わかっていますが、何らかの理由で最適なソリューションを使用できない場合があります。 –

関連する問題