0

アプリで薄い色のストライプを作成しようとしています。これは、カレンダー アプリで見られるさまざまな色のストライプに似ています。

それを行う簡単な方法はありますか。

私がやっていること:幅と高さで定義された形状があり、ListView の特定の部分を占めるため、ListView の背景に適用しようとしています。

何が起こっているか: これは背景全体に適用されています。

必要なもの: これを完全な背景ではなくストライプにすることができるヘルプを探しています。または、同じことを行うための他の方法または代替手段。

いくつかのコード: rectangle.xml

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

    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <corners 
        android:radius="0dp"
        />
    <size 
        android:width="20dp"
        android:height="40dp"       />
    <solid 
        android:color="@color/opaque_red"
        />
</shape>

list_view_item_cell.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="95dp"
    android:divider="?android:dividerVertical"

    android:showDividers="middle" >

より明確にするために写真を投稿する:

4

2 に答える 2

4

色付きの背景が必要な特定の部分に等しい幅と高さのビューを追加できます。たとえば、幅と高さ = 20dip の色付きストリップを表示する場合。この色付きのストリップは、リスト項目の左上に表示されます。以下はサンプルです

list_view_item_cell.xml

<?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="95dp"
        android:divider="?android:dividerVertical"
        android:showDividers="middle" >
<!-- You can use any view here. Set background "rectangle.xml" drawable to this view.-->
    <View  
        android:layout_width="20dip" 
        android:layout_height="20dip"
        android:background="@drawable/rectangle"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        />

    </RelativeLayout>
于 2014-08-21T04:43:54.810 に答える
2

はい、形状の色をプログラムで変更できます。

ビューの背景に設定された LayerDrawable があると仮定します: 次に、これはあなたができることです:

LayerDrawable layerList = (LayerDrawable) view.getBackground();
    if(layerList != null) {
        final RotateDrawable shape = (RotateDrawable) layerList
                .findDrawableByLayerId(R.id.header_titled);
        final GradientDrawable tildShapeDrawable = (GradientDrawable)shape.getDrawable();
        if (tildShapeDrawable != null) {
            tildShapeDrawable.setColor(android.R.color.white);
        }
    }
于 2014-08-21T05:51:47.947 に答える