0

I try to make my application for different resolution and screen size. For layouts I use weights and it works perfectly but have problem with texts and icons (Vector Assets in androidstudio). Actually I use constant value for texts(e.g 20sp) and icons(e.g 20dp) but when application is open in another mobile icons are too small or too big. Is it possible to scale it by screen size in xml file?

<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"
tools:context="com.hgyghyfghyu.apkana40.TrainerMenu"
android:orientation="vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp">

//
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="2"
    android:background="#000000"
    android:layout_marginBottom="10dp"
    android:id="@+id/colorsdialogbtn">
</LinearLayout>

//
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="2"
    android:layout_marginBottom="10dp"
    android:layout_marginTop="10dp"
    android:orientation="horizontal">
    //
    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#000000"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:id="@+id/trainermenugroupsbtn">
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/trainermenugroupsicon"
                android:tint="#FFFFFF"
                android:layout_centerInParent="true"
                android:src="@drawable/trainermenugroupsicon"/>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_below="@+id/trainermenugroupsicon"
                android:textSize="25dp"
                android:textStyle="bold"
                android:text=""
                android:textColor="#FFFFFF"/>
        </RelativeLayout>
    </LinearLayout>
    //
    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#000000"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:id="@+id/trainermenutrainersbtn">
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/trainermenutrainersicon"
                android:tint="#FFFFFF"
                android:layout_centerInParent="true"
                android:src="@drawable/trainermenutrainersicon"/>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_below="@+id/trainermenutrainersicon"
                android:textSize="25dp"
                android:textStyle="bold"
                android:text=""
                android:textColor="#FFFFFF"/>
        </RelativeLayout>
    </LinearLayout>

</LinearLayout>

//
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:layout_marginTop="10dp"
    android:layout_marginBottom="10dp"
    android:orientation="horizontal">
    //
    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="2"
        android:background="#000000"
        android:id="@+id/trainermenuadbtn"
        android:layout_marginRight="10dp"
        android:layout_marginLeft="10dp"
        android:layout_marginBottom="10dp">
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:paddingTop="10dp">
            <ImageView
                android:id="@+id/trainermenuadicon"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:tint="#FFFFFF"
                android:src="@drawable/trainermenuadicon"
                android:layout_alignParentTop="true"
                android:layout_centerHorizontal="true"/>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/trainermenuadicon"
                android:layout_centerHorizontal="true"
                android:textSize="15dp"
                android:text=""
                android:textStyle="bold"
                android:textColor="#FFFFFF"/>
        </RelativeLayout>
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="2"
        android:orientation="horizontal"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp">
        //info
        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#000000"
            android:id="@+id/trainermenuinfobtn"
            android:layout_marginRight="10dp"
            android:layout_marginBottom="10dp">
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">
                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:tint="#FFFFFF"
                    android:src="@drawable/trainermenuinfoicon"
                    android:layout_centerInParent="true"/>
            </RelativeLayout>
        </LinearLayout>


        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#000000"
            android:id="@+id/trainermenusettingsbtn"
            android:layout_marginLeft="10dp"
            android:layout_marginBottom="10dp">
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">
                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:tint="#FFFFFF"
                    android:layout_centerInParent="true"
                    android:src="@drawable/trainermenusettingicon"/>
            </RelativeLayout>
        </LinearLayout>
    </LinearLayout>
</LinearLayout>

littlewombat
  • 299
  • 2
  • 8
  • 22
  • mmm I think that you haven't a good `xml` design... – Aspicas Apr 06 '16 at 14:48
  • If your xml were well designed, your pictures automatically would scale – Aspicas Apr 06 '16 at 14:50
  • I put xml file in my post. Could you suggest whats is wrong? – littlewombat Apr 06 '16 at 14:57
  • Let me see, wait a moment please. – Aspicas Apr 06 '16 at 14:58
  • Yes, I think that you shouldn't use a `RelativeLayout` for your `trainergroups`, you need to use the same with you use in other elements, `LinearLayouts` with `weight` property and your images automatically would scale – Aspicas Apr 06 '16 at 15:08
  • You can download a plugin to automatically scale images in diferents folders to diferents screens size but redesigns your `xml` first. the plugin name it's `Android Drawable Importer` – Aspicas Apr 06 '16 at 15:15
  • I'm beginner in xml, I wanted to use LinearLayouts for weights and then use Relative Layout for place image/text in center. So if I need to place image in Linyout center (with scale) I should create 9 LinearLayouts(3x3) and then put image in LinearLayout number 5 (in center of this 3x3)? – littlewombat Apr 06 '16 at 15:16
  • mmm... more and less... but for empty layouts (without icons or text) don't use `Linear, use FrameLayouts`. and you can use only 6 layouts. Frame, Linear (with 3 layouts inside) and another Frame. – Aspicas Apr 06 '16 at 15:23

0 Answers0