Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to locate the checkbox at the center of a button vertically
    primarykey
    data
    text
    <p>I have a checkbox implemented in xml and locate the checkbox xml on top of a button.</p> <p></p> <p>custom_checkbox.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;item android:state_checked="true" android:drawable="@xml/checked" /&gt; &lt;item android:state_pressed="true" android:drawable="@xml/checked" /&gt; &lt;item android:drawable="@xml/unchecked" /&gt; &lt;/selector&gt; </code></pre> <p>checked.xml</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"&gt; &lt;gradient android:startColor="#ffff0000" android:endColor="#ff000000" android:angle="270"/&gt; &lt;stroke android:width="4dp" android:color="#ffc0c0c0" /&gt; &lt;size android:height="20dp" android:width="20dp"/&gt; &lt;/shape&gt; </code></pre> <p>unchecked.xml</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"&gt; &lt;gradient android:startColor="#ff585858" android:endColor="#ff000000" android:angle="270"/&gt; &lt;stroke android:width="4px" android:color="#ffc0c0c0" /&gt; &lt;size android:height="20dp" android:width="20dp"/&gt; &lt;/shape&gt; </code></pre> <p>The checkbox is located on top of a button as shown in the attached image. How can I center the checkbox vertically in the xml? Thanks</p> <p>EDIT 1: My layout xml is</p> <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" 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=".SettingActivity" &gt; &lt;Button android:id="@+id/activation" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background ="@color/green_gradient" android:textSize="20sp" style="@style/ButtonText" android:layout_marginTop="32dp" android:text="@string/activation" /&gt; &lt;Button android:id="@+id/overspeed" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_marginTop="46dp" android:textSize="20sp" android:background ="@color/green_gradient" style="@style/ButtonText" android:text="@string/overspeed" /&gt; &lt;CheckBox android:id="@+id/overspeedcheckBox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:button="@xml/custom_checkbox" /&gt; &lt;Button android:id="@+id/autoupdate" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/overspeed" android:layout_below="@+id/overspeed" android:textSize="20sp" android:background ="@color/green_gradient" style="@style/ButtonText" android:layout_marginTop="22dp" android:text="@string/autoupdate" /&gt; &lt;CheckBox android:id="@+id/autoupdatecheckBox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:button="@xml/custom_checkbox"/&gt; &lt;Button android:id="@+id/movementdetect" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/autoupdate" android:background ="@color/green_gradient" android:textSize="20sp" style="@style/ButtonText" android:layout_centerVertical="true" android:text="@string/movement" /&gt; &lt;CheckBox android:id="@+id/movementdetectcheckBox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:button="@xml/custom_checkbox"/&gt; &lt;Button android:id="@+id/geofence" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/movementdetect" android:background ="@color/green_gradient" android:layout_below="@+id/movementdetect" android:textSize="20sp" style="@style/ButtonText" android:layout_marginTop="32dp" android:text="@string/geofence" /&gt; &lt;CheckBox android:id="@+id/geofencecheckBox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:button="@xml/custom_checkbox"/&gt; &lt;Button android:id="@+id/passwordchange" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background ="@color/green_gradient" android:textSize="20sp" style="@style/ButtonText" android:layout_marginTop="32dp" android:text="@string/changepassword" /&gt; &lt;Button android:id="@+id/passwordreset" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background ="@color/green_gradient" android:textSize="20sp" style="@style/ButtonText" android:layout_marginTop="32dp" android:text="@string/passwordreset" /&gt; &lt;Button android:id="@+id/timezonechange" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background ="@color/green_gradient" android:textSize="20sp" style="@style/ButtonText" android:layout_marginTop="32dp" android:text="@string/timezonechange" /&gt; &lt;CheckBox android:id="@+id/timezonecheckBox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:button="@xml/custom_checkbox"/&gt; &lt;Button android:id="@+id/simnumberchange" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background ="@color/green_gradient" android:textSize="17sp" style="@style/ButtonText" android:layout_marginTop="32dp" android:text="@string/simnumberchange" /&gt; &lt;Button android:id="@+id/authorizenumber" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background ="@color/green_gradient" android:textSize="19sp" style="@style/ButtonText" android:layout_marginTop="32dp" android:text="@string/authorizenumber" /&gt; &lt;CheckBox android:id="@+id/authorizenumbercheckBox" android:layout_width="wrap_content" android:layout_height="wrap_content" android:button="@xml/custom_checkbox"/&gt; &lt;Button android:id="@+id/checkstatus" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background ="@color/green_gradient" android:textSize="20sp" style="@style/ButtonText" android:layout_marginTop="32dp" android:text="@string/checkstatus" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p><img src="https://i.stack.imgur.com/W93sr.jpg" alt="enter image description here"></p>
    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.
    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