Can someone explain the correct way to use android:layout_toRightOf?

by Jonathan Nalewajek » Thu, 31 Dec 2009 04:56:07 GMT


Sponsored Links
  little background info: I am a C++ developer who has worked very
little with Java. Picking up Java wasn't very difficult since I know C+
+, but I am still playing around with the SDK. (In C++, my favorite
SDK/API is Qt)

Anyway, I am trying to stick to the Model-View-Controller design
philosophy, and was setting up the UI in XML. However, it is not
working out the way I wanted it too. I am trying to write a simple app
(to help get started with learning the SDK), where there are 4
buttons, all of which cause a different operation on a value in a
textview. For example, the textview starts out at 100, and I have 4
buttons: +1, -1, +5, -5. When you press +1, it adds 1 to the value in
the textview. When you press -5, it subtracts 5 from the value in the
textview, etc etc...

That part is working fine. However, I am trying to setup the UI as
follows:

[TextView]
[+1] [-1]
[+5] [-5]

Basically, I want all the + in one column, and all the - in another
column. I figured I would use a relativeLayout, however, it is not
working the way I want it to. I am getting the following
[TextView] [-5]
[+1]
[+5]
(the -1 button is totally missing)

I have tried to narrow down possible errors in my code, and I have
come to the conclusion that either I am using android:layout_toRightOf
wrong, or I misunderstand how this command is implemented.

Here is my main.xml file:
(note: bu1p = button for +1, bu1m = button for -1 [p=positive
m=minus]. I also have a custom button in there, so there are really 6
buttons in total)

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id = "@+id/nums"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize = "20sp"
android:text = "100"
/>
<Button
android:id = "@+id/bu1p"
android:layout_width="70sp"
android:layout_height="wrap_content"
android:text = "+1"
android:layout_below="@id/nums"
/>
<Button
android:id = "@+id/bu1m"
android:layout_width="70sp"
android:layout_height="wrap_content"
android:text = "+1"
android:layout_toRightOf="@id/bu1p"
/>

<Button
android:id = "@+id/bu5p"
android:layout_width="70sp"
android:layout_height="wrap_content"
android:text = "+5"
android:layout_below="@id/bu1p"
/>
<Button
android:id = "@+id/bu5m"
android:layout_width="70sp"
android:layout_height="wrap_content"
android:text = "-5"
android:layout_toRightOf="@id/bucm"
/>
<Button
android:id = "@+id/bucp"
android:layout_width="70sp"
android:layout_height="wrap_conte



Can someone explain the correct way to use android:layout_toRightOf?

by Chander Pechetty » Thu, 31 Dec 2009 17:07:17 GMT


 ere's a partial layout for your case. Use the layout_below along with
RightOf and the text for the minus button was "+".
If you don't use that, then all of them are to the right of the
specified layout id , but not below the same parent as the id's
parent.

<Button
android:id = "@+id/bu1m"
android:layout_width="70sp"
android:layout_height="wrap_content"
android:text = "-1"
android:layout_below="@id/nums"
android:layout_toRightOf="@id/bu1p"
/>

You can also use a LinearLayout to represent you horizontal elements,
and specify the layout_below at this level.(ie. Plus and Minus button
in horizontal linear layout which is below the TextView)
Tip: Move the common attributes of a View to a style.xml file so that
you can change all of them in one go.
style="@style/button_style" where button_style is defined in
style.xml






On Dec 30, 8:02am, Jonathan Nalewajek <jonnalewa...@gmail.com> wrote:

--


Sponsored Links


Can someone explain the correct way to use android:layout_toRightOf?

by jotobjects » Fri, 01 Jan 2010 01:41:49 GMT


 



You cannot have a forward reference in the layout.    Here bucm is
later in the layout so that forward reference is not allowed.

--



Can someone explain the correct way to use android:layout_toRightOf?

by Jonathan Nalewajek » Fri, 01 Jan 2010 04:46:19 GMT


 hank you, this worked!

I was thinking toRightOf literally meant, "put the object to the right
of the object specified". I was thinking it carried over the y-
coordinate, and just added some value to the x-coordinate. However,
you need to specify x and y coordinate relations.

On Dec 31, 4:07am, Chander Pechetty <cspeche...@gmail.com> wrote:

--



Other Threads

1. changing the name i guess?

Hi i was wondering if anyone knew like basically i create an app

HelloWorld

so what i want to do is have another app with the same code on the
phone but under a new name while still keeping the original app so i
would have

HelloWorld
HelloWorldTest

when i just change the app_name the phone only keeps

HelloWorldTest

do i have to create a whole seperate projects if i want to do this im
trying to keep it one

-- 

2. media codec manipulation -?

Hello,
I am working on media streamer H263/ AAMR-NB for Android phones where i need
an option for manipulation of video compression parameters ( quality
and grayscale vs . color).
Can someone suggest a solution implementable within Android SDK?
I have done it before with FFMPEG/ Linux, but can I use FFMPEG on
Android for camera capture?
I am not sure if video4linux is available in Android version of kernel.
Thanks,
-V

-- 

3. Device idea

4. Same audio sample rates for input and output from application to driver level

5. android support for 18bpp lcd display

6. third party drivers

7. [beagleboard] TI Android FroYo DevKit V 2.2 for Beagle XM and AM37x/DM3730 EVMs