Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid RelativeLayout placing elements whith styles
    text
    copied!<p>I want to place two elements in line, one to the right and one to the left. I want to do this from the code... and use styles.</p> <p>First I tried it with static layout.xml: This works good:</p> <pre><code> &lt;RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" &gt; &lt;TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:text="@string/hello_world" /&gt; &lt;TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:text="TextView" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>then I created styles,</p> <pre><code> &lt;style name="t1" parent="@android:style/TextAppearance.Large"&gt; &lt;item name="android:layout_width"&gt;wrap_content&lt;/item&gt; &lt;item name="android:layout_height"&gt;wrap_content&lt;/item&gt; &lt;item name="android:layout_alignParentLeft"&gt;true&lt;/item&gt; &lt;/style&gt; &lt;style name="t2" parent="@android:style/TextAppearance.Large"&gt; &lt;item name="android:layout_width"&gt;wrap_content&lt;/item&gt; &lt;item name="android:layout_height"&gt;wrap_content&lt;/item&gt; &lt;item name="android:layout_alignParentRight"&gt;true&lt;/item&gt; &lt;/style&gt; </code></pre> <p>and tried:</p> <pre><code>RelativeLayout rel = new RelativeLayout(this); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); rel.setLayoutParams(params); TextView t1 = new TextView(this); t1.setText("balbla_1"); t1.setTextAppearance(this, R.style.t1); TextView t2 = new TextView(this); t2.setText("balbla_2"); t2.setTextAppearance(this, R.style.t2); rel.addView(t1); rel.addView(t2); setContentView(rel); </code></pre> <p>But I see elements overlapping, as the style for align was not accepted... is it possible to use styles for such procedures?</p>
 

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