Tela Responsivas

Asked

Viewed 1,038 times

1

I’m having doubts about responsive screens on android. I’m almost done with my app, but I’m not getting it to be responsive to 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.

inserir a descrição da imagem aqui

  • Could you complement with some sample code you’re using...

  • There are several ways to make a layout adjustable to various screen dimensions. Each of them depends on the layout content (images for example) and even the type of application. That’s why your question was closed as "too broad". If the question has only to do with this screen post the xml of your layout.

  • 1

    The question is still closed so I can’t answer it. The problem with your layout is that, although you use a Relativelayout, you are, to position the buttons, using fixed positioning attributes such as marginTop, marginLeft and not relative as layout_alignParentLeft, layout_toRightOf, etc.

  • Hello, how did you manage to make the buttons so round,?

1 answer

1

Always follow the conventions on Android best coding practices, they were taken for a reason and you don’t need to reinvent the wheel, that’s certainly the best attitude you can take.

Speaking briefly, you will have to create "the same" Activity for each type of device you want to meet. And at home Activity use the different Sources 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 which choice to show.

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:

  • You will need to better read the content of links which he indicated because, in his reply, I do not think he understood that the code he posted is not necessary if the "Screen Size Selector"

  • Thanks for the feedback, corrected reply.

  • Eduardo Silva, this 600 (config.smallestScreenWidthDp >= 600) that you have in the code is worth screens larger than 600 dp?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.