-1

I have a (RelativeLayout) layout xml that was designed to work for 10 inch tablets. I now want the very same layout to be displayed when the app runs on a phone. Instead of it being only displayed partly, I want it to be scaled, so that the structure is the same, just everything a bit smaller.

I have already:

  • Searched the web - without a result
  • Read about LayoutInflaters - but have no idea where I could set a scale there
  • Tried to "override" the defaultWindow's density using Reflection - without a result

Please note that I am aware that this is bad practice, but it's just a personal project and I am curious to know if this is possible.

Any help is highly appreciated!

EDIT: What I want is to really scale the screen as a whole. I am not the author of the original layout, as it's an open source project for tablets that I want to use on my phone. Here is the source: https://github.com/amigold/Gui2Go The layout I am talking about is main.xml.

FD_
  • 12,947
  • 4
  • 35
  • 62
  • Android scales pretty well on its own. It's difficult to guess what you did wrong unless you include your layout. – 323go Mar 17 '13 at 16:43
  • You are aware of the irony of wanting to avoid GUI design for an app that facilitates GUI design, right? – 323go Mar 17 '13 at 17:06

1 Answers1

1

My reputation is too low to ask you to include a sample layout, and my proposal does not use the exact same layout. However, You can create layouts with the same id tags and filename.xml having the 10 inch tablet version in the folder res/layout-sw600dp and the phone version in res/layout. The layout in /layout-sw600dp will be automatically used for larger screens & the layout in /layout will be used for smaller screens. You will not have to change your setContentView() call at all.

see: http://developer.android.com/guide/practices/screens_support.html

  • Yeah, I know about that. My problem rather is the creation of that phone layout. The tablet layout contains many sublayouts, and, as it's just a personal project, I thought that scaling the layout (emulating a different DPI) would be the easiest and fastest solution. – FD_ Mar 17 '13 at 17:00
  • I figured you had a particular need to do it programatically, but I thought I should throw this out there just in case. – Patrick Griffin Mar 17 '13 at 17:05
  • Thanks for your help anyway ;) I've added a link to the project (it's an open source tablet project by someone else that I wanted to use on my phone). As you can see, the layout is quite complex. – FD_ Mar 17 '13 at 17:08