c# - Change layout size depends on Screen size -
i'm new in android programming. wrote small app. when launched on 4.7" screen device looks small. how can make autoscaling different sizes of screen?
my xml:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:weightsum="100" android:layout_width="wrap_content" android:layout_height="wrap_content" android:minwidth="25px" android:minheight="25px"> <framelayout android:layout_width="wrap_content" android:layout_height="267.9dp" android:weight="100" android:id="@+id/framelayout1"> <imageview android:src="@drawable/fone" android:layout_width="match_parent" android:layout_height="match_parent" android:scaletype="centercrop" android:id="@+id/imageview1" /> <linearlayout android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="140dp" android:id="@+id/linearlayout1" android:layout_marginbottom="0.0dp"> <imagebutton android:src="@android:drawable/ic_menu_gallery" android:layout_width="49.0dp" android:layout_height="50.8dp" android:id="@+id/privatebutton" android:layout_marginright="98.9dp" android:background="#00000000" /> <imagebutton android:src="@drawable/logo" android:layout_width="75.3dp" android:layout_height="64.1dp" android:id="@+id/logobutton" android:layout_marginright="113.7dp" android:background="#00000000" /> <imagebutton android:src="@android:drawable/ic_menu_gallery" android:layout_width="49.0dp" android:layout_height="50.8dp" android:id="@+id/cartbutton" android:background="#00000000" /> </linearlayout> </framelayout> <linearlayout android:orientation="horizontal" android:minwidth="25px" android:minheight="25px" android:layout_width="match_parent" android:layout_height="142.7dp" android:id="@+id/linearlayout2"> <button android:text="Суші" android:layout_width="192.8dp" android:layout_height="fill_parent" android:id="@+id/button1" android:background="@drawable/sushi" android:textcolor="#ffffff" android:textsize="20sp" android:textstyle="bold" /> <button android:text="Роли" android:layout_width="192.8dp" android:layout_height="fill_parent" android:id="@+id/button2" android:background="@drawable/rolli" android:textcolor="#ffffff" android:textsize="20sp" android:textstyle="bold" /> </linearlayout> <linearlayout android:orientation="horizontal" android:minwidth="25px" android:minheight="25px" android:layout_width="match_parent" android:layout_height="142.7dp" android:id="@+id/linearlayout3"> <button android:text="Сети" android:layout_width="192.8dp" android:layout_height="match_parent" android:id="@+id/button3" android:background="@drawable/sets" android:textcolor="#ffffff" android:textsize="20sp" android:textstyle="bold" /> <button android:text="Холодні Закуски" android:layout_width="192.8dp" android:layout_height="match_parent" android:id="@+id/button4" android:background="@drawable/holodni" android:textcolor="#ffffff" android:textsize="20sp" android:textstyle="bold" /> </linearlayout> <linearlayout android:orientation="horizontal" android:minwidth="25px" android:minheight="25px" android:layout_width="match_parent" android:layout_height="70.2dp" android:id="@+id/linearlayout4" android:layout_marginleft="0.0dp"> <linearlayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="65dp" android:background="#f2565c" android:id="@+id/linearlayout5"> <imagebutton android:src="@drawable/back" android:layout_width="49.0dp" android:layout_height="50.8dp" android:id="@+id/previousbutton" android:layout_marginright="120.8dp" android:background="#00000000" android:layout_margintop="8.6dp" android:clickable="true" /> <imagebutton android:src="@drawable/home" android:layout_width="49.0dp" android:layout_height="50.8dp" android:id="@+id/homebutton" android:layout_marginright="117.5dp" android:background="#00000000" android:layout_margintop="7.4dp" android:clickable="true" /> <imagebutton android:src="@drawable/next" android:layout_width="49.0dp" android:layout_height="50.8dp" android:id="@+id/nextbutton" android:layout_marginleft="0.0dp" android:background="#00000000" android:layout_margintop="8.6dp" android:clickable="true" /> </linearlayout> </linearlayout> </linearlayout>
and should written in xml or in main activity?
if want application support different screen sizes should try use views not mocked values like:
android:layout_height="140dp"
but play values: match_parent & wrap_content, example:
android:layout_height="wrap_content" android:layout_width="match_parent"
to align components play gravity , layout_gravity properties. example:
android:layout_gravity="center_horizontal" android:gravity="center"
Comments
Post a Comment