Android Community
Results 1 to 5 of 5

Thread: Absolut Layout

  1. #1
    Join Date
    Mar 2011
    Posts
    2

    Default Absolut Layout


    Hi guys,

    I have a question about Layouts in Android v2.2.
    But first some information about the language I'm using.
    Language: Java
    IDE: Eclipse
    I want to define my ui components in the code. I know thats nothing special and it works great until it comes to the locationsettings.
    I want to define the location of my ui controls absolut.
    But at these points i have some trouble, because each of the regular android controls I've tested doesn't support properties like setlocation() or things like setx() or sety().
    It's really nessesary for me that i can do that in my code and not in that annoying xml "layout" file.

    Greets
    Gateway

  2. #2
    Join Date
    Feb 2010
    Location
    NY
    Posts
    121

    Default Re: Absolut Layout

    What are you trying to do exactly? A.ndroid is designed around relative positions and not absolute x and y.

    It can be tough to get your head around at first but it's well worth it in the end.

    Some must-reads:

    1) http://developer.android.com/guide/t...t-objects.html

    2) http://developer.android.com/resourc...ews/index.html

    3) http://stackoverflow.com/questions/2...-sp-in-android

    4) http://developer.android.com/guide/p...s_support.html


    If you must set positions in code, you can use things like

    ViewGroup.LayoutParams
    http://developer.android.com/referen...outParams.html

    and its subclasses like:

    ViewGroup.MarginLayoutParams
    http://developer.android.com/referen...outParams.html

    Where you can set marginLeft and marginTop (which are sort of like x and y)
    my apps: BlueMuze | Listables
    If I help you with a dev or Android question, please check out my apps
    t:@alostpacket w:http://alostpacket.com/

  3. #3
    Join Date
    Mar 2011
    Posts
    2

    Default Re: Absolut Layout

    Hi,

    I want to do it like I do it regular with java and swing.
    I mean like this for example:

    Code:
     
    package
    
    Main; import
    javax.swing.*; public
    class example {
    /**
    *
    @param args
    */
    //Controls privatestatic JFrame win; privatestatic JButton btn_OK; privatestatic JButton btn_Cancel; publicstaticvoid main(String[] args) { // TODO Auto-generated method stub init(); win.setVisible(true); } publicstaticvoid init(){ win = new JFrame("Window 1"); win.setLayout(null); win.setSize(500, 500); btn_OK = new JButton("Ok"); btn_OK.setSize(70, 25); btn_OK.setLocation(win.getWidth() - 90, win.getHeight() - 55); win.add(btn_OK); btn_Cancel = new JButton("Cancel"); btn_Cancel.setSize(70, 25); btn_Cancel.setLocation(win.getWidth() - btn_OK.getWidth() - 100, win.getHeight() - 55); win.add(btn_Cancel); }
    }
    It's much more comfortable for me as to define some words like left and right into a xml file. You know what I mean? I need something where I can calculate with.

    Excuse me for my low englisch skills, I don't have to use it very often.

    Greets
    Gateway

  4. #4
    Join Date
    Feb 2010
    Location
    NY
    Posts
    121

    Default Re: Absolut Layout

    Well A.ndroid doesnt support swing, but you can write layouts in code, it's just not as common.

    Read the links I posted and most of the XML attributes you can use to layout objects have an equivalent Java method you can use if you created the object in code.
    my apps: BlueMuze | Listables
    If I help you with a dev or Android question, please check out my apps
    t:@alostpacket w:http://alostpacket.com/

  5. #5
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    2

    Default Re: Absolut Layout


    I agree with alostpacket. Your approach is all wrong. You have to go with the flow, and learn to do things the Android way. You are not going to get anywhere by trying to impose a methodology that you have inherited from another platform.

    Android layouts are a bit like CSS. Everything is done implicitly. It takes a while to get your head round it, but it is well worth it in the long run.

Similar Threads

  1. How can i command my view layout?
    By dgrafix in forum General Phone Chat
    Replies: 9
    Last Post: 12-17-2010, 11:33 PM
  2. Wallpaper Layout Done!!!
    By uga.buga in forum Developers Guild
    Replies: 24
    Last Post: 10-05-2008, 04:57 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •