Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can </p> <ul> <li>use a <code>TableLayout</code> inside a <code>HorizontalScrollView</code>, or </li> <li>stay with your approach with an horizontal <code>LinearLayout</code> but adding vertical <code>LinearLayout</code>s instead of directly the images. E.g., adding three to four images per vertical <code>LinearLayout</code> in portrait, and redrawing to add only two in landscape.</li> </ul> <p>I would try the <code>TableLayout</code> approach first.</p> <p>PS1: for next time, try to remove all the non-relevant code (the less code is there, the easier is to understand what you did).</p> <p>PS2: Remember that <code>System.out</code> is usually redirected to <code>/dev/null</code> and thus lost, so I strongly suggest you to use <code>Log.d</code> instead.</p> <h2>Complete example</h2> <p>Adapt this to the onCreate() method or wherever you need it:</p> <pre><code>public void horizontalScrollGalleryLayout () { HorizontalScrollView sv = new HorizontalScrollView(this); LinearLayout llh = new LinearLayout(this); llh.setOrientation(LinearLayout.HORIZONTAL); LinearLayout.LayoutParams layoutParamsTV = new LinearLayout.LayoutParams(40, 40); LinearLayout.LayoutParams layoutParamsLL = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); for (int i=0; i&lt;20; i++) { LinearLayout llv = new LinearLayout(this); llv.setOrientation(LinearLayout.VERTICAL); TestView testView1 = new TestView(this, Color.rgb(i*12, 0, 0)); TestView testView2 = new TestView(this, true, Color.rgb(i*12, i*12, 0)); TestView testView3 = new TestView(this, true, Color.rgb(0, i*12, 0)); llv.addView(testView1, layoutParamsTV); llv.addView(testView2, layoutParamsTV); llv.addView(testView3, layoutParamsTV); llh.addView(llv, layoutParamsLL); } sv.addView(llh, layoutParamsLL); setContentView(sv); } </code></pre> <p>I'm using a very simple View as an example:</p> <pre><code>public class TestView extends View { Context context; int color; public TestView(Context context, int color) { super(context); this.context = context; this.color = color; } @Override public void onDraw (Canvas canvas) { super.onDraw(canvas); this.setBackgroundColor(Color.LTGRAY); Paint paint = new Paint (Paint.ANTI_ALIAS_FLAG); paint.setColor(color); canvas.drawCircle(20, 20, 20, paint); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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