开发者

Managing Android layouts, there must be a better way

I'm trying to sort the layout for one of my Android apps, but I'm finding layouts a nightmare.

Principally I have to have a portrait and landscape layout for normal, small and large screens. So thats 6 layouts to maintain to start with, let alone having to launch the app on three emulators each time because my UI widets don't load in the built in prev开发者_Go百科iewer.

I might be showing my ignorance as a fairly new developer, but there must be a better way!

Are there any tools out there to help with Android layouts?

Thanks


You dont need to have that many layouts. Design only as many as you need, and never use absolute values, aditionally try to make everything look nice using fill_parent and wrap_content for you layout_width & layout_height tags. Android does most of the work it self. This article contains a lot of usefull info: Supportng multiple screens


You may find this applicaiton helpful for designing your layouts:

http://www.droiddraw.org/

Also, if you don't specify a layout for each rotation, android will use one - infact it can use one for everything. If you use fixed values it makes it much harder. Try using fill_parent and wrap_content, you android will take care of scaling the view for each screen type and rotation too.

As a tip, don't forget to include:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">

above your relative or linear layout, and:

</ScrollView>

at the end - that way if the view doesn't fit on the screen (ie too much content) it will allow the user to scroll.


Eclipse's built in layout "editor" shows a reasonably good example of what a layout looks like. I would assume you're writing your application in Eclipse. If not, I highly recommend it. While not perfect, it's the best environment I've found.


you just need to master the proper use of RelativeLayout's and LinearLayout's. Almost all of my Layouts will start with a Relative and have Linear nested inside. I generally don't use LinearLayouts without having either height or width set to 0 and using the weight attribute to make everything the same size.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜