Group Group Group Group Group Group Group Group Group

raywenderlich.com Forums

Adaptive UI in Android Tutorial

Learn how to use layouts to create apps that look great across many different form-factors of Android devices in this adaptive UI in Android tutorial.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/1429-adaptive-ui-in-android-tutorial

Hey, thanks for the tutorial.

In the tutorial, you seem to flip between calling the layout folder either res/layout-sw400dp or res/layout-w400dp. Is the sw400dp just a typo as it would mean something different than just w400dp?

I’m having difficultly in trying to figure out how I should organize my layout files. From your example, what if you had a device that is greater than 500dp in portrait mode? What would be the be folder setup to ensure you have the over-under layout for portrait mode and side-by-side layout for landscape mode on this device?

Thanks for the tutorial. It helped no end and makes the transition to the official Android documentation, on the subject, a little easier. Great initial motivation of the subject matter.

Thank you so much James! This tutorial help me a lots! Simple and easy to understand!

SupportMapFragment in fragment_info.xml is making the emulator crash.

Some updates…

  • To use SupportMapFragment.getMap() you must use

com.google.android.gms:play-services:7.8.0

and not a newer version. (Current newest is 9.8.0, but getMap() will not work

  • To not have a cast error for

mapFragment = ((SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map));

in InfoFragment.java, you must import

import android.support.v4.app.Fragment;

If you import android.app.Fragment the app will crash on startup.

  • In order to zoom to the location on the map as shown in the image, loadMap of InfoFragment.java needs to be:

private void loadMap(GoogleMap googleMap) {
if (googleMap != null) {
// Use green marker icon
BitmapDescriptor defaultMarker = BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE);
// listingPosition is a LatLng point
LatLng sceneryPosition = new LatLng(44.22438242, 6.944561);
// Create the marker on the fragment
mapFragment.getMap().addMarker(new MarkerOptions()
.position(sceneryPosition)
.icon(defaultMarker));
CameraPosition cameraPosition = new CameraPosition.Builder().target(sceneryPosition).zoom(10.0f).build();
CameraUpdate cameraUpdate = CameraUpdateFactory.newCameraPosition(cameraPosition);
mapFragment.getMap().moveCamera(cameraUpdate);
}
}

Hey, I couldn’t find New/Scaled drawable when right-clicking res/drawable. I am using Android Studio 2.2 and I have installed Android drawable importer too.