Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This simple app will layout 15 icons in three rows dynamically using RelativeLayout. There is no reason to use AbsoluteLayout - it is also deprecated.</p> <p>The main activity.</p> <pre><code>public class MainActivity extends Activity { private int mWidth; private int mTile; private int mColMax = 5; private Context mContext; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mContext = this; // the screen width is need to work out the tile size mWidth = mContext.getResources().getDisplayMetrics().widthPixels; // how wide (and high) each icon will be to fit the screen. mTile = (mWidth / mColMax); setContentView(R.layout.activity_main); // layout the icons initUI(); } /** * Layout 15 icon images in three rows dynamically. */ private void initUI() { // this is the layout from the XML ViewGroup layout = (ViewGroup) findViewById(R.id.main_layout); ImageView iv; RelativeLayout.LayoutParams params; int i = 0; int row = 0; int col = 0; do { params = new RelativeLayout.LayoutParams(mTile,mTile); params.setMargins((col * mTile), (row * mTile), 0, 0); iv = new ImageView(mContext); iv.setAdjustViewBounds(true); iv.setScaleType(ScaleType.FIT_CENTER); iv.setImageResource(R.drawable.ic_launcher); iv.setLayoutParams(params); layout.addView(iv); if (col == mColMax) { row++; col = 0; } else { col++; } } while (++i &lt;= 16); } } </code></pre> <p>And the layout XML.</p> <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/main_layout" android:layout_width="match_parent" android:layout_height="match_parent"&gt; &lt;/RelativeLayout&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    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. 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