Responsive Screens

1

I am having doubts about responsive screens on android. I'm almost finishing my app, but I'm not able to make it responsive to the various screen sizes. I'm using the Android Studio IDE.

<RelativeLayout 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=".MainActivity">

<Button
    android:layout_width="120dp"
    android:layout_height="120dp"
    android:layout_marginTop="70dp"
    android:layout_marginLeft="30dp"
    android:id="@+id/button_home_calcular"
    android:background="@drawable/botao_calcular_efeito" />

<Button
    android:layout_width="120dp"
    android:layout_height="120dp"
    android:layout_marginTop="70dp"
    android:layout_marginLeft="205dp"
    android:id="@+id/button_home_aluno"
    android:background="@drawable/botao_aluno_efeito" />

<Button
    android:layout_width="120dp"
    android:layout_height="120dp"
    android:layout_marginTop="300dp"
    android:layout_marginLeft="30dp"
    android:id="@+id/button_home_fluxograma"
    android:background="@drawable/botao_fluxograma_efeito" />

<Button
    android:layout_width="120dp"
    android:layout_height="120dp"
    android:layout_marginTop="300dp"
    android:layout_marginLeft="200dp"
    android:id="@+id/button_home_notas"
    android:background="@drawable/botao_notas_efeito" />

</RelativeLayout>

This image is an example of my layout.

    
asked by anonymous 13.03.2015 / 19:35

1 answer

1

Always follow the best coding conventions for Android , they were taken for a reason and you do not have to reinvent the wheel, that's certainly the best attitude you can take.

Speaking briefly, you will have to create "same" activity for each type of device you want to attend. And at home activity use the different resources for each screen size. For example: layout-hdpi and layout-xhdpi , drawable-hdpi and drawable-xhdpi , etc. The code below was taken from the first source of this question and shows an example of this choice of which activity to display.

public class MyActivity extends Activity {
    @Override protected void onCreate(Bundle savedInstanceState) {
        super.onCreate();
        Configuration config = getResources().getConfiguration();

        if (config.smallestScreenWidthDp >= 600) {
            setContentView(R.layout.main_activity_tablet);
        } else {
            setContentView(R.layout.main_activity);
        }
    }
}

Sources:

13.03.2015 / 19:59