0

First let me start with I have read the following which describes how to support multiple screens:

http://developer.android.com/guide/practices/screens_support.html

Show a list view on the left and detail on right when tablet, and using list view as activity and going to new activity for detail view makes perfect sense to me.

However I have a couple slightly different use cases that I cannot find answers to in the android docs.

  1. I have a 'view' I want to show. For a tablet (or bigger phone) I want to show this in a dialog. On smaller devices it should be a view within a new activity.

  2. I have a map view with markers. On a tablet (or bigger phone) I want to show a popover on marker click. On smaller devices I want to navigate to a new detail activity.

Android docs talk a lot about using size based layouts to solve these problems.

For #1 is there a way on a query action click to show a dialog vs a full screen activity/fragment based on layout files for different screen sizes? I know that I can wait for the action click, determine the screen size and if small go to activity if big show dialog. However I don't see google recommending that in docs anywhere.

Same for #2. Is there a way with layout files to show map popover on marker click vs new activity/fragment based on layout files for different screen sizes? Again I can wait til marker click and determine screen size and if/else what to do.

For both cases my Activity is a view with a map fragment in it. My layout is pretty much the same for all screen sizes. Just that I want to do different things based on actions (marker click, action bar item click) for different screen sizes.

lostintranslation
  • 23,756
  • 50
  • 159
  • 262

1 Answers1

0

Look at this document and read the example from Google and this answer.
You can use difference layouts for difference sizes by using values folder.
For example:

res/values-large/layout.xml (tablet)

<resources>
     <item name="main" type="layout">@layout/tablet_layout</item>
     <bool name="isTablet">true</bool>
</resources>

res/values-sw600dp/layout.xml (tablet)

<resources>
     <item name="main" type="layout">@layout/tablet_layout</item>
     <bool name="isTablet">true</bool>
</resources>

res/values/layout.xml (for phone)

<resources>
     <item name="main" type="layout">@layout/phone_layout</item>
     <bool name="isTablet">false</bool>
</resources>

From your activity:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
}

Detect phone or tablet from code:

boolean tabletSize = getResources().getBoolean(R.bool.isTablet);
if (tabletSize) {
    // do something
} else {
   // do something else
}

Hope this can help!
P/s: If you want separate layout for difference phone sizes, you can refer this link

Community
  • 1
  • 1
ductran
  • 10,043
  • 19
  • 82
  • 165