xml - Android: Possible Bug in Android -


i have 2 views using arrange buttons on screen. screen size seeing result on moto g in landscape mode - 640dp * 360dp. problem - buttons arranging them according view id=center_parent instead of the 1 id=left_corner

 <?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent">      <view android:id="@+id/center_parent"       android:layout_centerinparent="true"       android:layout_width="0dp"       android:layout_height="0dp"/>     <view android:id="@+id/left_corner"       android:layout_width="0dp"       android:layout_height="0dp"       android:layout_toleftof="@+id/center_parent"       android:layout_marginright="165dp"       android:layout_above="@+id/center_parent"       android:layout_marginbottom="150dp"       android:layout_alignparenttop="true"/>"     <button android:id="@+id/btn1"       android:layout_height="20dp"       android:layout_width="20dp"       android:padding="0dp"       android:layout_torightof="@+id/left_corner"       android:layout_marginleft="165dp"       android:layout_below="@+id/left_corner"       android:layout_margintop="5dp"       android:text="1"       android:textcolor="@android:color/black"       android:background="@drawable/star"/>     <button android:id="@+id/btn2"       android:layout_height="20dp"       android:layout_width="20dp"       android:padding="0dp"       android:layout_torightof="@+id/left_corner"       android:layout_marginleft="330dp"       android:layout_below="@+id/left_corner"       android:layout_margintop="171dp"       android:text="2"       android:textcolor="@android:color/black"       android:background="@drawable/star"/>      <button android:id="@+id/btn3"       android:layout_height="20dp"       android:layout_width="20dp"       android:padding="0dp"       android:layout_torightof="@+id/left_corner"       android:layout_marginleft="292dp"       android:layout_below="@+id/left_corner"       android:layout_margintop="171dp"       android:text="3"       android:textcolor="@android:color/black"       android:background="@drawable/star"/>      <button android:id="@+id/btn4"       android:layout_height="20dp"       android:layout_width="20dp"       android:padding="0dp"       android:layout_torightof="@+id/left_corner"       android:layout_marginleft="292dp"       android:layout_below="@+id/left_corner"       android:layout_margintop="292dp"       android:text="4"       android:textcolor="@android:color/black"       android:background="@drawable/star"/>  </relativelayout>! 

attached image of how looks on screen. though arrows show measure using left_corner, not case. if replace left_corner center_parent in buttons while arranging result same.

the marked arrow left_corner

i have found alternative. alternative not looking for. love learn explanation of this.

the layout_marginleft , layout_marginright much.

remove margins first, see view properly. start addding margins again accordingly.

there few things need observer here.

layout_marginbottom pushing left_corner far center_parent

layout_marginright pushing left_corner far center_parent have make mind on want controls places , aligned what.

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent">      <view android:id="@+id/center_parent"       android:layout_centerinparent="true"       android:layout_width="10dp"       android:layout_height="10dp"/>     <view android:id="@+id/left_corner"       android:layout_width="10dp"       android:layout_height="10dp"       android:layout_toleftof="@+id/center_parent"       android:layout_marginright="10dp"       android:layout_above="@+id/center_parent"       android:layout_marginbottom="10dp"       android:layout_alignparenttop="true"/>"     <button android:id="@+id/btn1"       android:layout_height="20dp"       android:layout_width="20dp"       android:padding="0dp"       android:layout_torightof="@+id/left_corner"       android:layout_marginleft="10dp"       android:layout_below="@+id/left_corner"       android:layout_margintop="0dp"       android:text="1"       android:textcolor="@android:color/black"       android:background="@drawable/star"/>     <button android:id="@+id/btn2"       android:layout_height="20dp"       android:layout_width="20dp"       android:padding="0dp"       android:layout_torightof="@+id/left_corner"       android:layout_marginleft="10dp"       android:layout_below="@+id/left_corner"       android:layout_margintop="20dp"       android:text="2"       android:textcolor="@android:color/black"       android:background="@drawable/star"/>      <button android:id="@+id/btn3"       android:layout_height="20dp"       android:layout_width="20dp"       android:padding="0dp"       android:layout_torightof="@+id/left_corner"       android:layout_marginleft="10dp"       android:layout_below="@+id/left_corner"       android:layout_margintop="40dp"       android:text="3"       android:textcolor="@android:color/black"       android:background="@drawable/star"/>      <button android:id="@+id/btn4"       android:layout_height="20dp"       android:layout_width="20dp"       android:padding="0dp"       android:layout_torightof="@+id/left_corner"       android:layout_marginleft="10dp"       android:layout_below="@+id/left_corner"       android:layout_margintop="60dp"       android:text="4"       android:textcolor="@android:color/black"       android:background="@drawable/star"/>  </relativelayout> 

using above xml, got below output. preview


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -