xml - Android - Calculator support all screen sizes -
i'm beginner on android app developing , have problem cannot find solution. i'm working app on nexus 5 , works perfect, no empty spaces between layouts, when switch nexus 4, happens ( using colors separate layouts) :
if switch pixel xl :
can doesn't have empty spaces on right?(below there xml code posted in case need it).
<linearlayout 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:background="@android:color/black" android:orientation="vertical" android:weightsum="1"> <linearlayout android:id="@+id/linearlayout1" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#f00"> <button android:id="@+id/button" android:layout_width="match_parent" android:layout_height="match_parent" android:onclick="onclickdtb" android:text="convert binary" android:textalignment="center" android:textallcaps="true" android:textsize="14sp" android:textstyle="bold|italic" /> </linearlayout> <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#0f0"> <textview android:id="@+id/textview" android:layout_width="match_parent" android:layout_height="98dp" android:layout_weight="0.01" android:fontfamily="serif-monospace" android:text="calculator" android:textalignment="textend" android:textcolor="@android:color/white" android:textsize="35dp" android:textstyle="bold" /> </linearlayout> <linearlayout android:layout_width="wrap_content" android:layout_height="match_parent" android:background="#f0f" android:orientation="horizontal"> <linearlayout android:layout_width="72.4dp" android:layout_height="match_parent" android:background="#ffa500" android:orientation="vertical"> </linearlayout> <linearlayout android:layout_width="72.4dp" android:layout_height="match_parent" android:background="#000fff" android:orientation="vertical"> </linearlayout> <linearlayout android:layout_width="72.4dp" android:layout_height="match_parent" android:background="#8b0000" android:orientation="vertical"> </linearlayout> <linearlayout android:layout_width="72.4dp" android:layout_height="match_parent" android:background="#800080" android:orientation="vertical"> </linearlayout> <linearlayout android:layout_width="72.4dp" android:layout_height="match_parent" android:background="#2e8b57" android:orientation="vertical"> </linearlayout> </linearlayout>
you must use weight , weight sum this
<linearlayout 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:background="@android:color/black" android:orientation="vertical" android:weightsum="1"> <linearlayout android:id="@+id/linearlayout1" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#f00"> <button android:id="@+id/button" android:layout_width="match_parent" android:layout_height="match_parent" android:onclick="onclickdtb" android:text="convert binary" android:textalignment="center" android:textallcaps="true" android:textsize="14sp" android:textstyle="bold|italic" /> </linearlayout> <linearlayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#0f0"> <textview android:id="@+id/textview" android:layout_width="match_parent" android:layout_height="98dp" android:layout_weight="0.01" android:fontfamily="serif-monospace" android:text="calculator" android:textalignment="textend" android:textcolor="@android:color/white" android:textsize="35dp" android:textstyle="bold" /> </linearlayout> <linearlayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="#f0f" android:weightsum="100" android:orientation="horizontal"> <linearlayout android:layout_width="0dp" android:layout_weight="20" android:layout_height="match_parent" android:background="#ffa500" android:orientation="vertical"> </linearlayout> <linearlayout android:layout_width="0dp" android:layout_weight="20" android:layout_height="match_parent" android:background="#000fff" android:orientation="vertical"> </linearlayout> <linearlayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="20" android:background="#8b0000" android:orientation="vertical"> </linearlayout> <linearlayout android:layout_width="0dp" android:layout_weight="20" android:layout_height="match_parent" android:background="#800080" android:orientation="vertical"> </linearlayout> <linearlayout android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="20" android:background="#2e8b57" android:orientation="vertical"> </linearlayout> </linearlayout> </linearlayout>
Comments
Post a Comment