How to limit a layout's width when on xlarge screens?
Question 1:
I have some XML-based layouts which work fine on phones. But when it comes to tablets, the layouts become very wide. There is nothing wrong with this, it just looks very ... unusual. So I'm thinking the easiest way to work around this is to limit the layout's width from XML (like using an attrib开发者_开发技巧ute "android:maxWidth="480dp") and be centered in the screen. But I can't find a way to do this, could somebody help?
(I thought about providing a "layout-xlarge" folder, but given the number of layouts I have, this is troublesome and adds to maintainence burden.)
Question 2:
On the 3.0 emulator, I saw that the original Settings app is, because of the extra-large screen, changed so that the screen is split into two parts. The left-hand parts shows the available settings, and the right-hand part shows the options of the selected setting. That is, the original two-level activities are now combined into one. My quesion is: Is there an easy way, without too much programming, to achieve this? What I expect is when the program detects that it's running on an xlarge screen, it calls some method and, voila, two activities become one. Is this possible? If not, how to achieve the lsef-right split screen?
Thank you.
The answer to both your questions is: Fragments
.
Fragments are Android's way of tackling large screen sizes - the basic idea is that what you can have layouts that adapt to small and large screens appropriately. On phones, you're probably used to having an activity correspond to a single screen's worth of content. On a tablet, this is a waste of space, and you often want to display several activities worth of content on a single screen.
Fragments
are similar activities
, but with a slightly different lifecycle. You still design your app around activities, but each activity can contain several fragments. Which of these fragments are shown on screen is up to you, and typically you show several at once on large screen devices.
Using the Android compatibility package
(downloaded through the Android SDk manager
) allows your app to run on older Android versions, including 2.1.
For an example, check out the API Demos: http://developer.android.com/resources/samples/Support4Demos/index.html
For general introduction to Fragments, read the API at: http://developer.android.com/guide/topics/fundamentals/fragments.html
精彩评论