Note that there are some explanatory texts on larger screens.

plurals
  1. POSet size of button with drawable background dynamically/programmatically
    text
    copied!<p>I have a button that has the following properties:</p> <p><strong>circle_normal.xml (in res/drawable)</strong></p> <pre><code>&lt;shape xmlns:android="http://schemas.android.com/apk/res/android" android:padding="10dp" android:shape="oval" &gt; &lt;solid android:color="#FF6347" /&gt; &lt;size android:height="325dp" android:width="325dp" /&gt; &lt;/shape&gt; </code></pre> <p><strong>circle.xml (in res/drawable)</strong></p> <pre><code>&lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;item android:drawable="@drawable/circle_pressed" android:state_pressed="true"/&gt; &lt;item android:drawable="@drawable/circle_normal"&gt;&lt;/item&gt; &lt;/selector&gt; </code></pre> <p><strong>activity_main.xml (in res/layout)</strong></p> <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/layout_main" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".Main" &gt; &lt;Button android:id="@+id/button_study" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:background="@drawable/circle" android:gravity="center" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p><strong>Main.java (in src)</strong></p> <pre><code>buttonStudy = (Button) findViewById(R.id.button_study); </code></pre> <p>The final product is that I get a button that is in the shape of a circle. However, due to the difference screen sizes on different Android devices, this one circle size is insufficient. I've looked at a few other questions similar to this but their solutions didn't help me very much. How do I change its size dynamically in the Java code?</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