Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would recommend you to use layout defined in xml to determine how the objects will look on the screen. When you define layouts in the xml you can use the logical unit of dp which is spacing according to the resolution of the screen. Like that (imagine you define that in file called <code>button_layout.xml</code>):</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="4dp"&gt; &lt;TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:textSize="16.0sp" /&gt; &lt;Button android:id="@+id/my_button" android:layout_width="wrap_content" android:layout_marginLeft="10dip" android:layout_marginRight="10dip"/&gt; &lt;/LinearLayout&gt; </code></pre> <p>Note that the <code>dp</code> and <code>dip</code> measurement units are synonyms.</p> <p>Then if you need to add one more button with together with all these elements programmatically you basically do something like:</p> <pre><code>LayoutInflater inflater; inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); LinearLayout linearLayout = (TableLayout) inflater.inflate(R.id.button_layout, null); linearLayout.findViewById(R.id.line_id).setText("One"); // Or two or three as you wish main_activity_layout.addView(linearLayout); //adding yet another button </code></pre> <p>This comes only as illustration how you use the layout. You can actually define the layout with the properties you need and also set programatically all case-by case specific properties. The most important thing is that: - You get easier to understand layout - You specify the margins and paddings etc in relative units of <code>dp</code>.</p> <p><strong>EDIT</strong>: If you really insist on this being done in code, <a href="https://stackoverflow.com/q/5012840/1108032">here</a> is how you specify dp programatically. Still I would recommend using the layout solution as much as possible.</p>
    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. 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