How to create "responsive layouts" on Android? [closed]

0

I'm wondering how to create a responsive "Layout" to serve on all devices smarts and tablets, so that the size of texts, buttons suit appropriately for each screen, what is the best and practical way to do this? / p>

Taking advantage of this, giving an example of the METEOR javascript framework, you can separate the html tags by templates so that you do not get the big code and each template or .html you separate by folders, it is possible to do something like this on Android?

    
asked by anonymous 03.12.2016 / 01:40

1 answer

2

I do not believe that to work as the Meteor in the scheme in Android , but Android has layouts that can be used by include,

Your main layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/app_bg"
    android:gravity="center_horizontal">

    <include android:id="@+id/news_title"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
             layout="@layout/title" />

    <TextView android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:text="@string/hello"
              android:padding="10dp" />
</LinearLayout>

Your reusable / reusable layout:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/titlebar_bg">

    <ImageView android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:src="@drawable/gafricalogo" />
</FrameLayout>

Read about on:

There are also Fragments, but they are a very specific case link

About "Reponsiveness"

Basically you will have to create a Layout for each size, this is not necessarily "responsive", but it works fine, you can create a layout for each screen like this:

res/layout/my_layout.xml              // telas normais (por defeito/por padrão)
res/layout-large/my_layout.xml        // telas largas
res/layout-xlarge/my_layout.xml       // telas muito largas
res/layout-xlarge-land/my_layout.xml  // telas muito largas e em landscape

More details at: link

Or you can try the hint of this answer in the SOen , if you need to do something with custom sizes you want, an example if the screen is larger than 600:

Configuration config = getResources().getConfiguration();

if (config.smallestScreenWidthDp >= 600) {
    setContentView(R.layout.main_activity_tablet); //activity para tablets
} else {
    setContentView(R.layout.main_activity); //activity normal
}

WebView as an application

There is also the possibility of using WebView to create a WebApp, but it really does not always pay off (it will depend a lot on the case), however if you want to use Meteor , Bootstrap and the like may try this answer:

03.12.2016 / 17:03