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. Reg: retrieving the phone number on an incoming call

Hello,
        Does somebody have an example or sample code for retrieving the
phone number on an incoming phone call.

Appreciate your help

-- Adonis

-- 

2. Elevating/Adding permissions by way of first uninstalling rather than updating an app

I have been noticing a trend in a small amount of applications that
cause a program to be uninstalled when it should merely be updating.

Always the same programs doing this, have fairly frequent updates,
most of the updates are "normal" and proceed, a few updates are
actually the app being uninstalled - no user intervention causing or
asking for an uninstall, only a normal from-market update!

Specifically:

Hypnotoad To Go (yesterday's update became uninstalled, dropped 2
permissions and added 1 permission)
Gowalla (Shows uninstalled, but is in fact still installed on device,
permissions increased once "re-installed" added 2 permissions - app
still functions)
Vignette (every time, adds or removes a permission each time
installed, but device still shows installed - app still works)
Chess.com (every update, becomes an uninstall, but has only added one
permission the first time - for full Internet access)
Wordpress (noted once, does not update often, and was the first time I
saw an app "do that")
Meridian Media Player (either a complete uninstall, or updated but
loses registration code everytime)

Becuase of these auto-uninstall (not asked for by user) methods, the
market has no way of knowing if and when permissions are changed,
whether dropped or added.  ZERO apps that have done this ever warn
that the program would be or might be uninstalled, they just look as
if they will merely be updated as usual.

I haven't found the 3 or so other apps that I have seen this behavior
from, but I will edit this post as-needed.

I do not believe this is a market issue, as the consistency of some
apps doing this (in these cases, all of them,  they are NOT marked as
Manual Update) belies that evidence.

On some of the more consistently "updated" apps, I have tried both
with an Update All approach, and as an individual update as it either
presented itself, or by my choise of individually updating on purpose
(when not chosing the Update All option).

Let's put it this way, IF all this is a market glitch, THEN it needs
fixing ASAP, as it affects the reputation of ALL developers and the
market.

The permissions I have a problem with being asked are generally:
Read Contact Data (rarely made specific)
Read System Logs

Why my concern?  Because MANY, if not, MOST apps ask on a per-needed
basis to send a crash report (with or  without a system log).  System
log access, and do not need a system log read - other than what
Android standard is given on a force close/report window - and rarely
needed to patch an app properly anyway, especially when all of the
apps that have recently requested this permission rarely crash!

Contact data also is only needed precisely WHEN and IF you want to
share a contact.  There is no reason to expect users to fell
"burdened" to check a box for each contact (the excuse sometimes
given, "it makes the user experience more streamlined".  Ya,
whatever.).

One additional, slightly related issue:
Programs, specifically like Meridian, request payment OUTSIDE of the
market.  The market should NEVER allow that.

Also, once an app is paid for, a later update that asks to elevate
unwarranted permissions, the user should be given a choice for a FULL
refund - no matter when the update or no matter how long a user has
had that app - OR Android should have natively built in methods for
blocking permissions with a choice box: for things like Full Internet
- when before was only needed for running ads, Contact reads, ANY data
writes, SD card moves/adds/deletes/writes, etc.  Apps that POLL should
most definitely be wrangled accordingly, as they are the most
offensive to batteries staying charged (rarely is it a "clear RAM"
issue, it can be a RAM issue as with the oldest Android devices, but
most of the newer models that is very rare).

-- 

3. Filtering based on fpu

4. I'm stuck and need some help with touchable widgets

5. ViewGroup with round angle

6. how to capture more than 2 Views?

7. Custom Account Preferences using AccountManager / AccountAuthenticators