Note that there are some explanatory texts on larger screens.

plurals
  1. POLayout: dynamic background
    text
    copied!<p>I'm creating app similar to this: </p> <p><img src="https://i.stack.imgur.com/Xzhgt.jpg" alt="enter image description here"></p> <p>Width of one hour is expressed in dp. How can I create such divided (by borders or by different colors) background? I though about inserting ImageViews but is there better method? Currently my layout:</p> <pre><code>&lt;HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/horizontalScrollView1" android:layout_width="fill_parent" android:layout_height="fill_parent"&gt; &lt;LinearLayout android:id="@+id/tableLayout" android:layout_width="wrap_content" android:layout_height="match_parent" android:orientation="vertical"&gt; &lt;RelativeLayout android:id="@+id/tableRowLayout1" android:layout_width="wrap_content" android:layout_height="wrap_content"&gt;&lt;/RelativeLayout&gt; &lt;RelativeLayout android:id="@+id/tableRowLayout2" android:layout_width="wrap_content" android:layout_height="wrap_content"&gt;&lt;/RelativeLayout&gt; &lt;/LinearLayout&gt; &lt;/HorizontalScrollView&gt; </code></pre> <p>And I insert elements to relative layouts.</p> <p>Thanks for help.</p> <p><strong>SOLUTION</strong></p> <pre><code> 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); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload