1

私はこれに似たアプリを作成しています:

ここに画像の説明を入力

1 時間の幅は dp で表されます。このような分割された (境界線または異なる色で) 背景を作成するにはどうすればよいですか? 私はImageViewsを挿入することについて考えましたが、より良い方法はありますか? 現在私のレイアウト:

<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/horizontalScrollView1" android:layout_width="fill_parent" android:layout_height="fill_parent">
    <LinearLayout android:id="@+id/tableLayout" android:layout_width="wrap_content" android:layout_height="match_parent" android:orientation="vertical">
        <RelativeLayout android:id="@+id/tableRowLayout1" android:layout_width="wrap_content" android:layout_height="wrap_content"></RelativeLayout>
        <RelativeLayout android:id="@+id/tableRowLayout2" android:layout_width="wrap_content" android:layout_height="wrap_content"></RelativeLayout>
    </LinearLayout>
</HorizontalScrollView>

そして、相対レイアウトに要素を挿入します。

手伝ってくれてありがとう。

解決

    HorizontalScrollView mainView = (HorizontalScrollView) findViewById(R.id.horizontalScrollView1);

    Point size = new Point();
    getWindowManager().getDefaultDisplay().getSize(size);

    int height = size.y;
    int width = dpToPixels(dpPerHour);

    Bitmap bmpBg = ((BitmapDrawable) getResources().getDrawable(R.drawable.schedule_bg)).getBitmap();
    Bitmap scaled = Bitmap.createScaledBitmap(bmpBg, width, height, true);
    BitmapDrawable viewBg = new BitmapDrawable(getResources(), scaled);
    viewBg.setTileModeX(TileMode.REPEAT);
    viewBg.setGravity(Gravity.LEFT);
    mainView.setBackground(viewBg);
4

2 に答える 2

1

水平に分離された白い領域の場合

<bitmap>タイリング経由で を使用できます(ソース drawable をタイリングしてandroid:tileMode="repeat"構築されたビットマップの一例)。

ちょっとした作業で、<shape>内側をタイル張りにすることができます。<bitmap>しかし、ドローアブル内の画像を並べて表示する<bitmap>方が簡単だと思います。

ボタン用

ボタンの外観を指定するために 9 パッチの使用を検討することをお勧めします。9 パッチを使用して、すべてのボタンに細い黒い境界線を付けることができます。または、<shape>drawable を使用することもできます。

于 2013-05-12T18:13:24.960 に答える