3

I am currently facing a trouble regarding size change.

I have coded my xml files using dp's, but when I change the device screen size, the layout would change.

For example, when I go into Settings - Display - Screen zoom and font and set screen zoom from medium to large, some of the elements in my layout such as imageview or button would grow and go beyond the screen.

Since I'm using a complex layout containing LinearLayouts and FrameLayouts, I am not clear about how I should make this layout look alright in any other devices or screen sizes. It seems like when I change the screen zoom setting, the value of dp changes.

Is there a way to avoid this problem, or maybe to programmatically set screen zoom setting to medium?

Here is my code:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:gravity="center"
    android:layout_gravity="center"
    android:layout_marginTop="65dp">

    <android.support.constraint.ConstraintLayout
        android:id="@+id/frameLayout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="95dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.3">

        <ImageView
            android:id="@+id/imageView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/home_map" />

        <Button
            android:id="@+id/pick1"
            android:layout_width="34dp"
            android:layout_height="56dp"
            android:background="@drawable/top_deselected"
            app:layout_constraintBottom_toBottomOf="@+id/imageView"
            app:layout_constraintEnd_toEndOf="@+id/imageView"
            app:layout_constraintHorizontal_bias="0.17"
            app:layout_constraintStart_toStartOf="@+id/imageView"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.18" />

        <Button
            android:id="@+id/pick2"
            android:layout_width="34dp"
            android:layout_height="56dp"
            android:background="@drawable/jungle_deselected"
            app:layout_constraintBottom_toBottomOf="@+id/imageView"
            app:layout_constraintEnd_toEndOf="@+id/imageView"
            app:layout_constraintHorizontal_bias="0.28"
            app:layout_constraintStart_toStartOf="@+id/imageView"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.367" />

        <Button
            android:id="@+id/pick3"
            android:layout_width="34dp"
            android:layout_height="56dp"
            android:background="@drawable/mid_deselected"
            app:layout_constraintBottom_toBottomOf="@+id/imageView"
            app:layout_constraintEnd_toEndOf="@+id/imageView"
            app:layout_constraintHorizontal_bias="0.424"
            app:layout_constraintStart_toStartOf="@+id/imageView"
            app:layout_constraintTop_toTopOf="@+id/imageView"
            app:layout_constraintVertical_bias="0.43" />

        <Button
            android:id="@+id/pick4"
            android:layout_width="34dp"
            android:layout_height="56dp"
            android:background="@drawable/support_deselected"
            app:layout_constraintBottom_toBottomOf="@+id/imageView"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.615"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="@+id/imageView"
            app:layout_constraintVertical_bias="0.71" />

        <Button
            android:id="@+id/pick5"
            android:layout_width="34dp"
            android:layout_height="56dp"
            android:background="@drawable/adc_deselected"
            app:layout_constraintBottom_toBottomOf="@+id/imageView"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.733"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="@+id/imageView"
            app:layout_constraintVertical_bias="0.71" />

    </android.support.constraint.ConstraintLayout>

    <Button
        android:layout_width="335dp"
        android:layout_height="42.5dp"
        android:layout_marginBottom="5.5dp"
        android:background="@drawable/home_mode"
        android:id="@+id/home_mode"/>

    <Button
        android:layout_width="335dp"
        android:layout_height="42.5dp"
        android:background="@drawable/home_match"
        android:id="@+id/home_match"/>

</LinearLayout>

The constraint layout used to be a frame layout, but I was just now trying out the constraint layout.

Andy K
  • 207
  • 2
  • 14

1 Answers1

4

You can also use this library, it is working on all devices, no need to make any dimen file and all. but use this only for the size of widgets, for text size use "sp" only.

https://github.com/intuit/sdp

Khyati Chitroda
  • 402
  • 1
  • 4
  • 16