Mastering Android layouts

How do I maintain a consistent layout for app layouts? By consistency, I mean proportion, readability, usability, and user friendliness.

I have been making Android apps for some time now. All of these applications were made for corporate clients. Each app was designed for a specific phone, so I don't have to go deep into layouts.

I recently received a request to build a complex app for all Android 2.2 devices up to 5.0. This requirement includes: ActionBar, Sliding Menu, Master / Detail Flow, Many Fragments, Many buttons, Maps, the list goes on. So I started my research.

Study

Firstly, to support all of the Views mentioned above, I decided to use appcompat_v7. Just because Google did it. Ditch ActionBarSherlock because it is a third party library.

Alternative layouts:

Under certain conditions, you need to use an alternate layout. It's easy to do this with an alias.

values-large / aliases.xml

<resources>
    <item name="main_layout" type="layout">@layout/main_latyout_large</item>
</resources>

      

This code will do it:

setContentView(R.layout.main_layout);

      

Act effectively like this

setContentView(R.layout.main_layout_large);

      

So far so good, but as will be seen later, something eludes me. (see finally)

Note. An alternative way is to place master_layout_large.xml as layout-large / master_layout.xml.

Forests, proportions

A trivial example:

Layout / master_layout.xml

<LinearLayout
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:weightSum="@dimen/layout_weightSum">
  <View 
     android:layout_width="match_parent"
     android:layout_height="0dp"
     android:layout_weight="@dimen/view1_weight"/>
  <View 
     android:layout_width="match_parent"
     android:layout_height="0dp"
     android:layout_weight="@dimen/view2_weight"/>
</LinearLatyout>

      

values ​​/ dimens.xml

<resources>
    <dimen name="layout_weightSum">1</dimen>
    <dimen name="view1_weight">0.2</dimen>
    <dimen name="view2_weight">0.8</dimen>
</resources>

      

This configuration allows me to easily change the aspect ratio like this:

For Android 2.2 to Android 3.1

values-small / dimens.xml

<resources>
    <dimen name="view1_weight">0.3</dimen>
    <dimen name="view2_weight">0.7</dimen>
</resources>

      

For Android 3.2 and higher:

values-sh240dp / dimens.xml

<resources>
    <dimen name="view1_weight">0.3</dimen>
    <dimen name="view2_weight">0.7</dimen>
</resources>

      

In How to support multiple screens :

The configuration qualifiers that you can use to provide size dependent resources are small, normal, large, and xlarge. For example, layouts for extra large screens should go to layout-xlarge /. As of Android 3.2 (API level 13), the aforementioned size groups are deprecated and you should instead use the swdp config qualifier to determine the smallest available width your layout resources need.

Then, How Android Calls a Best-Fit Resource explains (by example) the resource selection process. What isn't said (or can't find) is how to drop deprecated qualifiers. (even if there is)

Q1: Should I use both methods in an application that requires all versions to work?

Q2: Can deprecated resource qualifiers (small, normal, etc.) match non-deprecated resource qualifiers?

Note. This scaffolding technique was taken from here .

Discreteness:

TextViews are disappointing. Nothing native that supports auto-resizing. WTF ?.

But suppose I am using the component of this answer. So I can use the same method, dimensions.

layout / other_layout.xml (related code)

<myns.AutoResizeTextView 
    android:id="@+id/title"
    android:textSize="@dimen/title_textSize"/>

      

values ​​/ dimens.xml

<resources>
    <dimen name="title_textSize">24dp</dimen>
</resources>

      

values-xlarge / dimens.xml

<resources>
    <dimen name="title_textSize">64dp</dimen>
</resources>

      

values-sw600dp / dimens.xml

<resources>
    <dimen name="title_textSize">64dp</dimen>
</resources>

      

Same problems as before, another problem arises here - showing the text at the optimal size for each screen, but it is more tedious because according to my tests, I need to define a lot of measurement options to make it look consistent across devices.

Q3: How easy is the readability to read?

Finally

I understand that the way I come across this project, it becomes necessary to create multiple values- * and exponentially account for the number of options. (view Providing Alternative Resources )

Q4: What can I do to minimize the number of - * values ​​that my application seems to need.

Any other suggestion?

+3


source to share





All Articles