私はこれに似たアプリを作成しています:
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);