java bridge - center a button

33 views
Skip to first unread message

Kevin Moran

unread,
Feb 24, 2012, 4:05:34 AM2/24/12
to android-progr...@googlegroups.com
How do you center a button (or an image for that matter) using Java bridge? I mean, you could create a horizontal arrangement, subtract the button width from the width of the Form, then divide that by 2 and put that value as margins on both sides but that seems really hacky to me. Is there a better way?

Thanks,
Kevin

M. Hossein Amerkashi

unread,
Feb 24, 2012, 11:45:31 AM2/24/12
to android-progr...@googlegroups.com
For Now:
      HorizontalArrangement hr = new HorizontalArrangement(this, LENGTH_FILL_PARENT);
      new Label(hr, "", LENGTH_FILL_PARENT, COLOR_NONE);
      Button buttonStart = new Button(this, "I'm centered");
      new Label(hr, "", LENGTH_FILL_PARENT, COLOR_NONE);

David W Wolber

unread,
Feb 24, 2012, 2:27:33 PM2/24/12
to android-progr...@googlegroups.com
Hossein, I think you mentioned to me that someone created some Java Bridge samples that allow you to create ui objects in the Android xml fashion. Is that with a different library? 

Kevin, I'm not suggesting we switch on this as far as building the tutorials apps, just want to know if its something that should be explored.

Dave

M. Hossein Amerkashi

unread,
Feb 25, 2012, 5:59:52 PM2/25/12
to android-progr...@googlegroups.com
Kevin,
Functionality added into bridge. Also, added functionality of a Splash screen.

-Hossein

M. Hossein Amerkashi

unread,
Feb 25, 2012, 6:01:23 PM2/25/12
to android-progr...@googlegroups.com
Forgot the link to show you how to setup splash:
See items 4 and 5 of http://code.google.com/p/apptomarket/wiki/AiBridgeNightly

Kevin Moran

unread,
Feb 26, 2012, 1:23:07 AM2/26/12
to android-progr...@googlegroups.com
Excellent, thanks Hossein.

Kevin

M. Hossein Amerkashi

unread,
Feb 26, 2012, 1:04:20 PM2/26/12
to android-progr...@googlegroups.com
David,

Bridge does not force to use of bridge components. For example, you can create a linear layout with a text label in there like the following:
setContentView(R.layout.mylaout);
TextView tv = (TextView) findViewById(R.id.myTextView);

where firstTextView is defined in your layout xml like:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="center_horizontal">
    <TextView
            android:id="@+id/myTextView"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center_horizontal"
            android:text="Hello"
            android:textSize="42sp" />
</LinearLayout>

Ryan Bis

unread,
Aug 12, 2012, 2:31:27 PM8/12/12
to android-progr...@googlegroups.com
Hi David,

  To answer your question, yes there is a java bridge library out there which allows the use of the GLE in Eclipse. I put out the Alternate Java Bridge library, which has become an Eclipse plugin. It can be used just like the original java bridge (coding all UI components), or you can use the GLE to drop them in (and "link" to them in code). It makes it much easier designing the UI, especially if you are trying to support multiple screen sizes. Note that for the AltBridge, resource files go in the standard SDK places (images into the drawable folders, sounds into the raw folder).

The plugin makes starting a new project trivial. It includes a new project wizard to automatically copy over the jar file, add it to the build path, and setup the original Form.

Wiki:
http://code.google.com/p/alternate-java-bridge-library/w/list

DL:
http://code.google.com/p/alternate-java-bridge-library/downloads/list

Ryan



On Friday, February 24, 2012 2:27:33 PM UTC-5, David W Wolber wrote:
Reply all
Reply to author
Forward
0 new messages