开发者

Different Layouts for Horizontal and Vertical for an Android app?

开发者 https://www.devze.com 2023-02-02 03:31 出处:网络
The optimum layout for controls might depend on the orientation.If I have a set of checkboxes or radio buttons they might fit well if I stack them vertically when the user holds the phone in a vertica

The optimum layout for controls might depend on the orientation. If I have a set of checkboxes or radio buttons they might fit well if I stack them vertically when the user holds the phone in a vertical orientation. But if the user flips to horizontal it might be better to arrange them into two shorter stacks side-by-side, instead of forcing the user to scroll.

Does Android have any UI guidelines that address whether it's acceptable to use different layouts 开发者_JAVA百科for vertical and horizontal? And if so, how would I implement it to use the same controls, i.e., the same ID's for both layouts?

Thanks in advance!


It is completely acceptable to use different layouts for horizontal and vertical. This is why Android provides the layout and layout-land folders for defining these.

If it makes sense to you and will be easier for the user to navigate, then do it.

To implement this, you create an xml file with the same name in both the layout and layout-land folders. You then specify the same android:id for each asset. For instance a textview would contain the same id in both xml files:

<TextView android:text="@string/SomeText" 
        android:id="@+id/TextView01" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content">
</TextView>

It's that simple.

0

精彩评论

暂无评论...
验证码 换一张
取 消