0

I'm designing an app with many images, buttons and textViews strewn across the screen. At the moment I am using the relative layout as it seemed the most flexible of the lot. However were I place my elements and their size is still restricted to being aligned with other elements. Even worse if an element changes size any elements aligned to it will also change size.

There must be a simple solution to this! Apple's nib files perform this so easily with an effortless drag and drop to any location; yet android appears to be stuck with restrictive table/linear/relative/grid layouts.

If possible can the solution be performed via eclipse. If not please guide me to the relevant documentation to learn to create my own layouts via xml, create a huge grid layout or whatever horrors await me :) Thanks

Declan McKenna
  • 4,321
  • 6
  • 54
  • 72

3 Answers3

1

I think what you want is something like an absolute layout tho these were deprecated a while ago, Im pretty sure you can still do this via a Relative layout, you don't necessarily need to align the via with another view, I guess you could just do something like this:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="70dp"
        android:layout_marginTop="82dp"
        android:src="@drawable/ic_launcher" />

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="172dp"
        android:layout_marginRight="84dp"
        android:src="@drawable/ic_launcher" />

</RelativeLayout>

all I'm doing here is aligning it with the side of the parent and having a margin between it

FabianCook
  • 20,269
  • 16
  • 67
  • 115
0

You can do what you ask with a Frame Layout and setting the position of each object. But do so at your own risk. The reason Apple nib files let you arbitrarily place objects is taht the aspect ratio of all their devices is the same. So your layouts just scale up and down evenly.

Android is a more diverse ecosystem, and you should try to embrace layouts that adapt to different screen sizes and orientations.

Plastic Sturgeon
  • 12,527
  • 4
  • 33
  • 47
  • Would doing what you suggested but using display pixels rather than pixels allow the layout to adapt to different screen sizes? Or will the same problems still be present? If they are not why was absolute layout not updated to include dps rather than pxs? – Declan McKenna Feb 10 '12 at 01:08
0

Take a look at Android custom layout and Android - How to draw a letter at a specific point?

Are you planning to only use the app on a single android device model? If yes, check AbsoluteLayout's Alternatives. (FrameLayout or RelativeLayout)

It's not a good idea to put "Anything Anywhere you want" since Android devices have a lot of different screen sizes and properties. The only option would be to define your own custom layout.

I actually really like the way Android tries to make your layout compatible with as much devices as it can using alignment and structured layout views.

The reason it's simple for Apple is that you're only targeting iPhone, which has a fixed screen properties accross all devices.

Hope it helps. Good luck.

Community
  • 1
  • 1
Nima
  • 6,383
  • 7
  • 46
  • 68