android - CheckBox spacing next to TextView and Button -


my checkbox seems screwing layout quite bit.

this want:

button  | checkbox  | textview 

but checkbox pushing textview way right

button  | checkbox  |                  textview 

my xml layout:

<linearlayout            android:layout_width="fill_parent"            android:layout_height="wrap_content"            android:orientation="horizontal"            android:layout_margintop="15dp">             <button                android:id="@+id/signin_button"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:padding="5dp"                android:layout_marginleft="7dp"                android:background="@layout/bordersignin"                android:textcolor="#ffffff"                android:text="@string/signin" />             <checkbox                android:id="@+id/staysignedin"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:text="@string/staysignedin" />             <textview                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_gravity="left|center"                android:text="stay signed in" />        </linearlayout> 

upadated code , still pushes text right. wieghts have no effect on horizontal movement of them.

           <button                android:id="@+id/signin_button"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_marginleft="10dp"                android:background="@layout/bordersignin"                android:padding="5dp"                android:text="@string/signin"                android:textcolor="#ffffff"                android:layout_weight="1" />              <checkbox          android:id="@+id/staysignedin"          android:layout_width="wrap_content"          android:layout_height="wrap_content"          android:layout_weight=".1"           android:text="@string/staysignedin" />        <textview          android:layout_width="wrap_content"          android:layout_height="wrap_content"          android:layout_weight="10"          android:text="stay signed in" />         </linearlayout> 

full solution -----------------------------------

<linearlayout         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:orientation="horizontal"         android:weightsum="1" >          <button             android:id="@+id/signin_button"             android:layout_width="0dp"             android:layout_height="wrap_content"             android:layout_margintop="40dp"             android:layout_weight=".8"             android:background="@layout/bordersignin"             android:padding="5dp"             android:text="@string/signin"             android:textcolor="#ffffff" />          <relativelayout             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_marginleft="25dp"             android:layout_margintop="40dp"             android:layout_weight=".2" >              <checkbox                 android:id="@+id/staysignedincheck"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:padding="6dp"                 android:text="@string/staysignedin" />              <textview                 android:id="@+id/staysignedintext"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_alignright="@id/staysignedincheck"                 android:layout_gravity="center"                 android:layout_margintop="9dp"                 android:text="stay signed in" />         </relativelayout>     </linearlayout> 

result sign in button, checkbox , , "stay signed in" textview

result

you have options here:

  1. change width of linearlayout android:layout_width="wrap_content". not fill whole width. don't know if desired setup.

  2. for 3 views use this: android:layout_weight="1". every view have same room. how codemagic said, should set height / width 0dp horizontal / vertical orientation of linearlayout prevent view drawn twice.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -