Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Yes, you can. It's simple! I do this because legacy (pre API Level 13) systems do not support the newer layout folder filters. Specifically, I need to distinguish QVGA (small) from WQVGA (normal) and other normal resolutions.</p> <p>Just add a variety of layout files to your layout and layout-land folders, e.g.</p> <pre><code>layout my_layout_default.xml my_layout_qvga.xml layout-land my_layout_default.xml my_layout_qvga.xml </code></pre> <p>Then, select the appropriate layout at run time:</p> <pre><code>protected void onCreate(Bundle savedInstanceState) { // Some code that uses DisplayMetrics to determine the screen type ScreenType st = Util.getScreenType(this); super.onCreate(savedInstanceState); setContentView(st == ScreenType.ST_QVGA ? R.layout.my_layout_qvga : R.layout.my_layout_default); // ... </code></pre> <p>You can add a tag to each layout to discover which one was actually loaded, if you like, e.g.</p> <pre><code>&lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/my_root_view" android:tag="st_port_QVGA" FrameLayout flRoot = (FrameLayout)findViewById(R.id.my_root_view); Object objTag = flRoot.getTag(); if (objTag instanceof String) { String strTag = (String)objTag; System.out.println("Tag = " + strTag); } </code></pre> <p>BTW, there's no reason why you cannot combine this technique with the usual resource qualifiers, e.g. add files like my_layout_default.xml to other folders.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload