2017-11-22 13 views
0

3色の縦線(黒10 dp、白match_parent、黒10 dp)を含むxmlファイルをバックグラウンドで作成できますか?カスタム背景xmlファイル

レイアウトのバックグラウンドプロパティでxmlファイルとして使用する必要があるので、レイアウトを3つの部分に分けて色付けすることは簡単ではありません。基本的に、9・パッチ・ジェネレータは、あなたが持っている任意のサイズで画像を受け入れますし、あなたの画像やコンテンツの特定の領域を伸ばすリソースを作成します

答えて

2

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/id_view" 
    android:layout_height="match_parent" 
    android:layout_width="match_parent" 
    android:orientation="vertical"> 

     <View 
      android:id="@+id/id_view_one" 
      android:layout_width="match_parent" 
      android:layout_height="10dp" 
      android:background="@android:color/black"/> 

     <View 
      android:id="@+id/id_view_two" 
      android:layout_below="@+id/id_view_one" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="@android:color/white"/> 

     <View 
      android:id="@+id/id_view_three" 
      android:layout_width="match_parent" 
      android:layout_height="10dp" 
      android:layout_alignParentBottom="true" 
      android:background="@android:color/black"/> 

</RelativeLayout> 

background.xmlを作成...これを試してみてください。そして、以下のようにあなたの必要なXMLファイルで

your_activityをbackground.xmlが含まれます。 xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/id_view" 
    android:layout_height="match_parent" 
    android:layout_width="match_parent"> 

    <include layout="@layout/back"/> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 


    </RelativeLayout> 

</RelativeLayout> 
+0

私はすでに絵を描いています(長い話ですが、バックグラウンドのために100%透明で灰色の中間になるために底面が必要です。) しかし、それはうまくいくはずです。 – Vadim

1

あなたは9枚のパッチ画像を作成するために、9・パッチ・ジェネレータを使用することができます。その後、簡単にインポートすることができます。 リンク:layout_widthとlayout_height値を切り替え、垂直セパレータを追加する

<View 
    android:layout_width="match_parent" 
    android:layout_height="1dp" 
    android:background="@android:color/darker_gray"/> 

https://romannurik.github.io/AndroidAssetStudio/nine-patches.html#&sourceDensity=320&name=example

+0

このリンクは質問に答えるかもしれませんが、ここでは答えの重要な部分を含めて参考にしてください。リンクされたページが変更された場合、リンクのみの回答は無効になります。 - [レビューから](/レビュー/低品質の投稿/ 18027809) –

+0

編集された回答を参照してください。 – HaroldSer

0

Iは通常水平線を追加するには、このコードを使用します。

関連する問題