2

I have a question about Android and I need your help. I have the following RadioButton:

<RadioButton
    android:id="@+id/r_Button_Standard"
    android:layout_width="95dp"
    android:layout_height="35dp"
    android:layout_weight="1"
    android:background="@drawable/background_selector"
    android:text="@string/radioButton_standard"
    android:checked="true"
    android:textColor="@drawable/text_selector"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.642"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    android:layout_marginLeft="10dp"
    app:layout_constraintVertical_bias="0.671" />

It looks like this:RadioButton Now Android Studio generates a warning telling me to use "Should use "sp" instead of "dp" for text sizes" and further tells "There are cases where you might need to use dp; typically this happens when the text is in a container with a specific dp-size. This will prevent the text from spilling outside the container. Note however that this means that the user's font size settings are not respected, so consider adjusting the layout itself to be more flexible."

So now my question is what to do? Basically the text is in a container and it should obviously not spill outside of it. So I think I should use dp. What is meant by 'more flexible layout`?

Comment: Altough 'IntelliJ Amiya' closed this question and gave a link to a question that according to his point of view anseres my question (Should use "sp" instead of "dp" for text sizes) I have to say that in fact it does NOT. I am talking about text within a container not about general text.

Update: Here is my XML layout file:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <ImageView
        android:id="@+id/imageView"
        tools:ignore="ContentDescription"
        android:layout_width="465dp"
        android:layout_height="262dp"
        android:scaleType="fitXY"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.0"
        app:srcCompat="@drawable/test_dish_1" />

    <TextView
        android:id="@+id/cocktailName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Test "
        android:textColor="#000000"
        android:textSize="28dp"
        android:textStyle="bold"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.482"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.434" />


    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Zutaten: Zutat_1, Zutat_2, Zutat_3,\n Zutat_4, Zutat_5, Zutat_6"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.489"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/textViewA"
        android:layout_width="95dp"
        android:layout_height="35dp"
        android:text="Option_2"
        android:textColor="#000000"
        android:textSize="22dp"
        android:textStyle="bold"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.012"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.671" />


    <ImageButton
        android:id="@+id/commentButton"
        android:layout_width="100dp"
        android:layout_height="50dp"
        android:background="@null"
        android:contentDescription="comment_Button"
        android:scaleType="fitCenter"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.799"
        app:srcCompat="@mipmap/comment" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/comment_TextView"
        android:textSize="18dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.025"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.729" />

    <CheckBox
        android:id="@+id/checkBox"
        android:layout_width="95dp"
        android:layout_height="35dp"
        android:checked="true"
        android:text="Check"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.967"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.761" />

    <Button
        android:id="@+id/ordering_button"
        android:layout_width="163dp"
        android:layout_height="72dp"
        android:background="@drawable/custom_button"
        android:text="Bestellen"
        android:textAllCaps="false"
        android:textColor="#121212"
        android:textSize="25sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.867" />


    <TextView
        android:id="@+id/textViewS"
        android:layout_width="95dp"
        android:layout_height="35dp"
        android:text="Option_1"
        android:textColor="#000000"
        android:textSize="22dp"
        android:textStyle="bold"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.012"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.584" />

    <LinearLayout
        android:background="#FFD600"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        android:id="@+id/bottom_layout"
        android:layout_width="0dp"
        android:layout_height="60dp">

        <Button
            android:id="@+id/button1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_margin="4dp"
            android:layout_weight="1"
            android:background="@drawable/test_dish_1"
            android:text="Back" />


        <Button
            android:layout_gravity="center_vertical"
            android:id="@+id/button2"
            android:layout_weight="1"
            android:text="Button2"
            android:layout_width="0dp"
            android:layout_margin="4dp"
            android:layout_height="wrap_content"/>


        <Button
            android:layout_gravity="center_vertical"
            android:id="@+id/button3"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:text="Button3"
            android:layout_margin="4dp"
            android:layout_height="wrap_content"/>

        <Button
            android:layout_gravity="center_vertical"
            android:id="@+id/button4"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:text="Button1"
            android:layout_margin="4dp"
            android:layout_height="wrap_content"/>

    </LinearLayout>

    <RadioGroup
        android:id="@+id/radioGroup_Size"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintVertical_bias="0.583"
        app:layout_constraintHorizontal_bias="0.862"

        app:layout_constraintTop_toTopOf="parent">




        <RadioButton
            android:id="@+id/r_Button_Small"
            android:layout_width="95dp"
            android:layout_height="35dp"
            android:layout_weight="1"
            android:background="@drawable/background_selector"
            android:text="Klein"
            android:textColor="@drawable/text_selector"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.319"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            android:layout_marginLeft="10dp"
            app:layout_constraintVertical_bias="0.584" />

        <RadioButton
            android:id="@+id/r_Button_Medium"
            android:layout_width="95dp"
            android:layout_height="35dp"
            android:layout_weight="1"
            android:background="@drawable/background_selector"
            android:checked="true"
            android:text="Normal"
            android:textColor="@drawable/text_selector"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.962"
            app:layout_constraintStart_toStartOf="parent"
            android:layout_marginLeft="10dp"
            app:layout_constraintTop_toTopOf="parent"

            app:layout_constraintVertical_bias="0.583" />

        <RadioButton
            android:id="@+id/r_Button_Large"
            android:layout_width="95dp"
            android:layout_height="35dp"
            android:layout_weight="1"
            android:background="@drawable/background_selector"
            android:text="Groß"
            android:textColor="@drawable/text_selector"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.962"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            android:layout_marginLeft="10dp"
            app:layout_constraintVertical_bias="0.584" />

    </RadioGroup>

    <RadioGroup
        android:id="@+id/radioGroup_alcohol"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintVertical_bias="0.671"
        app:layout_constraintHorizontal_bias="0.872"

        app:layout_constraintTop_toTopOf="parent">

        <RadioButton
            android:id="@+id/r_Button_Less"
            android:layout_width="95dp"
            android:layout_height="35dp"
            android:layout_weight="1"
            android:background="@drawable/background_selector"
            android:text="Weniger"
            android:textColor="@drawable/text_selector"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.319"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.671" />

        <RadioButton
            android:id="@+id/r_Button_Standard"
            android:layout_width="95dp"
            android:layout_height="35dp"
            android:layout_weight="1"
            android:background="@drawable/background_selector"
            android:text="@string/radioButton_standard"
            android:checked="true"
            android:textColor="@drawable/text_selector"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.642"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            android:layout_marginLeft="10dp"
            app:layout_constraintVertical_bias="0.671" />

        <RadioButton
            android:id="@+id/r_Button_More"
            android:layout_width="95dp"
            android:layout_height="35dp"
            android:layout_weight="1"
            android:background="@drawable/background_selector"
            android:text="Mehr"
            android:textColor="@drawable/text_selector"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.962"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            android:layout_marginLeft="10dp"
            app:layout_constraintVertical_bias="0.671" />


    </RadioGroup>
</android.support.constraint.ConstraintLayout>
VanessaF
  • 515
  • 11
  • 36

2 Answers2

1

Read this article to fully understand SP, DP and Piexel:

Medium Article

TL;DR

SP == DP , but user preferences for font size in device setting app will also be applied to

Consider a user has increased font size in settings and probably he would like to see a higher font size inside your app, sp would take care of that.

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <ImageView
        android:id="@+id/imageView"
        android:layout_width="0dp"
        android:layout_height="250dp"
        android:scaleType="fitXY"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/test_dish_1"
        tools:ignore="ContentDescription" />

    <TextView
        android:id="@+id/cocktailName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        android:text="Test "
        android:textColor="#000000"
        android:textSize="28dp"
        android:textStyle="bold"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.482"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/imageView" />


    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:text="Zutaten: Zutat_1, Zutat_2, Zutat_3,\n Zutat_4, Zutat_5, Zutat_6"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.489"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/cocktailName" />

    <TextView
        android:id="@+id/textViewA"
        android:layout_width="95dp"
        android:layout_height="35dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="32dp"
        android:text="Option_2"
        android:textColor="#000000"
        android:textSize="22dp"
        android:textStyle="bold"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textViewS" />


    <ImageButton
        android:id="@+id/commentButton"
        android:layout_width="100dp"
        android:layout_height="50dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:background="@null"
        android:contentDescription="comment_Button"
        android:scaleType="fitCenter"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView2"
        app:srcCompat="@mipmap/comment" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="16dp"
        android:text="@string/comment_TextView"
        android:textSize="18dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.025"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textViewA" />

    <CheckBox
        android:id="@+id/checkBox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="16dp"
        android:checked="true"
        android:text="Check"
        app:layout_constraintBottom_toTopOf="@+id/ordering_button"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/radioGroup_alcohol" />

    <Button
        android:id="@+id/ordering_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:background="@drawable/custom_button"
        android:padding="16dp"
        android:text="Bestellen"
        android:textAllCaps="false"
        android:textColor="#121212"
        android:textSize="25sp"
        app:layout_constraintBottom_toTopOf="@+id/bottom_layout"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent" />


    <TextView
        android:id="@+id/textViewS"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="32dp"
        android:text="Option_1"
        android:textColor="#000000"
        android:textSize="22dp"
        android:textStyle="bold"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView3" />

    <LinearLayout
        android:background="#FFD600"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        android:id="@+id/bottom_layout"
        android:layout_width="0dp"
        android:layout_height="60dp">

        <Button
            android:id="@+id/button1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_margin="4dp"
            android:layout_weight="1"
            android:background="@drawable/test_dish_1"
            android:text="Back" />


        <Button
            android:layout_gravity="center_vertical"
            android:id="@+id/button2"
            android:layout_weight="1"
            android:text="Button2"
            android:layout_width="0dp"
            android:layout_margin="4dp"
            android:layout_height="wrap_content"/>


        <Button
            android:layout_gravity="center_vertical"
            android:id="@+id/button3"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:text="Button3"
            android:layout_margin="4dp"
            android:layout_height="wrap_content"/>

        <Button
            android:layout_gravity="center_vertical"
            android:id="@+id/button4"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:text="Button1"
            android:layout_margin="4dp"
            android:layout_height="wrap_content"/>

    </LinearLayout>

    <RadioGroup
        android:id="@+id/radioGroup_Size"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="32dp"

        android:layout_marginEnd="8dp"
        android:orientation="horizontal"
        app:layout_constraintBottom_toBottomOf="@+id/textViewS"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@+id/textViewS"
        app:layout_constraintTop_toBottomOf="@+id/textView3">


        <RadioButton
            android:id="@+id/r_Button_Small"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_weight="1"
            android:background="@drawable/background_selector"
            android:padding="4"
            android:text="Klein"
            android:textColor="@drawable/text_selector"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.319"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.584" />

        <RadioButton
            android:id="@+id/r_Button_Medium"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_weight="1"
            android:background="@drawable/background_selector"
            android:checked="true"
            android:padding="4dp"
            android:text="Normal"
            android:textColor="@drawable/text_selector"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.962"
            app:layout_constraintStart_toStartOf="parent"

            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.583" />

        <RadioButton
            android:id="@+id/r_Button_Large"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_weight="1"
            android:background="@drawable/background_selector"
            android:padding="4dp"
            android:text="Groß"
            android:textColor="@drawable/text_selector"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.962"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.584" />

    </RadioGroup>

    <RadioGroup
        android:id="@+id/radioGroup_alcohol"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginTop="32dp"

        android:layout_marginEnd="8dp"
        android:orientation="horizontal"
        app:layout_constraintBottom_toBottomOf="@+id/textViewA"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@+id/textViewA"
        app:layout_constraintTop_toBottomOf="@+id/radioGroup_Size">

        <RadioButton
            android:id="@+id/r_Button_Less"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/background_selector"
            android:padding="4dp"
            android:text="Weniger"
            android:textColor="@drawable/text_selector"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.319"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.671" />

        <RadioButton
            android:id="@+id/r_Button_Standard"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_weight="1"
            android:background="@drawable/background_selector"
            android:checked="true"
            android:padding="4dp"
            android:text="@string/radioButton_standard"
            android:textColor="@drawable/text_selector"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.642"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.671" />

        <RadioButton
            android:id="@+id/r_Button_More"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_weight="1"
            android:background="@drawable/background_selector"
            android:padding="4dp"
            android:text="Mehr"
            android:textColor="@drawable/text_selector"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.962"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.671" />


    </RadioGroup>
</android.support.constraint.ConstraintLayout>
Arrowsome
  • 2,649
  • 3
  • 10
  • 35
  • Thanks ramtintoosi for your comment. Basically I understand that I should use sp for text. But in my case the text in inside a container (RadioButton) and even Android Studio tells that in such a case dp could be used. However, I am wondering what is meant by 'consider adjusting the layout itself to be more flexible' from Android Studio – VanessaF May 17 '20 at 14:09
  • @VanessaF By what you describe to me, it means to let the android to size and draw views on the screen, so make your width and height WRAP_CONTENT, you are currently using fixed width and height and that can mess the layout up. – Arrowsome May 17 '20 at 14:13
  • Thanks ramtintoosi for your comment. Unfortunately I do not undestand what you are saying. I use the ConstrainedLayout and I have RadioButtons in them. Within the RadioButtons there is text (see the picture I posted). I use dp in this context as I do not want the text to be displayed outside the RadioButton when someone scales up. – VanessaF May 17 '20 at 14:16
  • @VanessaF I updated the answer, What do you mean by when user scales it up? – Arrowsome May 17 '20 at 14:20
  • Thanks ramtintoosi for your comment. I can't use your updated code because I have many Radio buttons that are aligned to each other and algined to other TextField. If I use 'warp content', the layout looks quite bad. This is why I have to use fixed dp for width and height. – VanessaF May 17 '20 at 14:26
  • @VanessaF So your design is the source of problems, you can post your design in your question and someone can help you. – Arrowsome May 17 '20 at 14:29
  • Thanks ramtintoosi for your comment. I posted the XML Layout file in my original question. Basically for me it is not a real problem. Everything works well and I tried it on the emulator. However, Android Studio just has a warning that I posted in my original question. I think it is better to use dp in my case – VanessaF May 17 '20 at 14:38
  • @VanessaF I edited your layout, there was lots of problem with it, consider the points I mentioned in my answer ;) please support my answer if it was helpful – Arrowsome May 17 '20 at 15:17
  • Thanks ramtintoosi for your answer and effort. Unforunately there are now linkebreaks in the Radiobuttons which look quite bad to be totally honest. And by the way, in my previous layout there were no real errors. I tested it many times and the layout looked exactly how I wanted. What do you mean by problems? To tell you the truth, I think that now I have a problem with the linebreaks whereas before everything was alright. Don't get me wrong. I really appreciate your help and effort (I voted your answer up). – VanessaF May 17 '20 at 15:39
  • Another very big problem with your layout is that I can't change anything using the Layout Editor. If I just move the bottoms or anyhting else a little bit, the whole layout looks extremely bad as it changes drastically. This is not so user friendly for layout disgners. If you use the constrainedLAyout and you just use constraines to the parents, as I did in my original layout, you can just drag and drop all the elements and it looks as it should look. – VanessaF May 17 '20 at 15:42
  • @VanessaF Migrate to AndroidX, I used `androidx.constraintlayout.widget.ConstraintLayout` to edit your layout. I haven't seen anyone using the technique you used for ConstraintLayout, but I guess it could lead to some layout inconsistency. using Guideline can be helpful the way you want to implement it. – Arrowsome May 17 '20 at 16:00
  • Thanks ramtintoosi for your comment. How can I 'Migrate to AndroidX'. When I use your code there are problems (as desribed in my previous two comments). And what do you mean by 'using Guideline can be helpful'. – VanessaF May 17 '20 at 16:07
  • Check `https://developer.android.com/jetpack/androidx/migrate` for AndroidX migration and check `https://constraintlayout.com/basics/guidelines.html` for Guideline tutorial. – Arrowsome May 17 '20 at 16:08
  • Basically my method of using the constrainedLayout is quite simple. You just constraine every component to the parents. Thus, you can simply drag and drop the element within your layout and you have full control over everything. So far I have not experienced any errors with that as long as you don't combine it with a ScrollView or something similar that scrolls the View. If you just have a non-scrollable layout my method has been working quite good and it is quite intuitive to design a layout with that. – VanessaF May 17 '20 at 16:09
  • 1
    @VanessaF just go with what you think is right and makes your development easier, I respect that ;) – Arrowsome May 17 '20 at 16:10
  • Thanks for your comment ramtintoosi. Okay then to come back to my origiona question you would also advice me to use dp instead of sp because otherwise the text could spill over. As said before I have to use a fixed width and height for the radio buttoms (your answer with the wrap content method does not seem to be suitable for me because of the linebreaks and the problems when changing something). – VanessaF May 17 '20 at 16:15
  • Unfortunately I do not have Linkedin. But we can just use the chat of Stackexchange for example – VanessaF May 17 '20 at 16:20
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/214063/discussion-between-vanessaf-and-ramtintoosi). – VanessaF May 17 '20 at 16:20
0

We prefer sp for texts on a screen because if the user wants to change the text size from settings (for example: small, medium, large) these texts are automatically scaled as per the screen. But in case of dp, every phone has different density of pixels ( for example: in a 4 x 4 square space, there may be 4 pixels in some phones and 16 pixels in some other phone), so it is not recommended to use dp.

  • Thanks Ankit for your comment. Basically I understand that I should use sp for text. But in my case the text in inside a container (RadioButton) and even Android Studio tells that in such a case dp could be used. However, I am wondering what is meant by 'consider adjusting the layout itself to be more flexible' from Android Studio – VanessaF May 17 '20 at 14:09