Relative Layout not compiling! - android

I was trying to do an adapter on a ListView as an exercise but I get a strange error on the row layout:
error: Error parsing XML: unbound prefix
What is wrong with this very simple Layout??!?
<?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="wrap_content">
<TextView
android:id="#+id/station"
android:text="Stazione DI"
android:layout_alignParentTop="true"
android:padding="3dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<TextView
androdi:id="#+id/time"
android:text="Time:"
android:layout_alignParentLeft="true"
android:below="#id/station"/>
<TextView
androdi:id="+id/late"
android:text="Time:"
android:layout_toRightOf="#id/time"
android:below="#id/station"/>
<TextView
androdi:id="+id/rail"
android:text="Rail:"
android:below="#id/station"
android:layout_toRightOf="#id/late"/>
</RelativeLayout>

Prefixes are those strings you type before the :, like android:.... And you typed it wrong once (androdi:...)
(edit: actually 3 times)

Prefixes in Last TextView spell not correct, check that

In xml file last Textview is worong
<TextView
androdi:id="+id/rail"
android:text="Rail:"
android:below="#id/station"
android:layout_toRightOf="#id/late"/>
It will be
<TextView
android:id="+id/rail"
android:text="Rail:"
android:below="#id/station"
android:layout_toRightOf="#id/late"/>

you have written android spelling wrong in following cases !
androdi:id="#+id/time"
androdi:id="+id/late"
androdi:id="+id/rail"

Related

Android XML error after updating eclipse

After recently updating eclipse i keep getting an error saying "Attribute name "android:tools" associated with an element type "RelativeLayout" must be followed by the ' = ' character.
It says it on line 9 but there isn't any android:tool there. I've tried cleaning and restarting eclipse and still no solution. I never changed any part of the file, and the funny thing is all my other activities are the same and don't have any errors. Any help would be appreciated thanks.
Edit... I fixed the problem by deleting the file and creating a new one. File must have been corrupt or something. Thanks for the input everyone, sorry for the run confusion.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/backtext"
tools:context=".Brakes"
android:screenOrientation="portrait" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="#string/brakes1"
android:textColor="#color/textviews"
android:textSize="15sp" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView2"
android:text="#string/brakes2"
android:textColor="#color/textviews"
android:textSize="15sp" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView3"
android:text="#string/brakes3"
android:textColor="#color/textviews"
android:textSize="15sp"/>
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView4"
android:text="#string/brakes4"
android:textColor="#color/textviews"
android:textSize="15sp"/>
</RelativeLayout>
</ScrollView>
Try moving this line:
xmlns:tools="http://schemas.android.com/tools"
to your ScrollView instead of the RelativeLayout where it is now.
it looks like your RelativeLayout used to be your root view, and you added the ScrollView at some point later.
you are missing xmlns:tools="http://schemas.android.com/tools" in your root parent,please include it.
Remove xmlns:android="http://schemas.android.com/apk/res/android" from your RelativeLayout. There should be only one of those at the layout root element.

Text view clipping of in android

I am using a custom Toast and sometimes the text view gets clipped off if the field is too long:
XML:
<?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="wrap_content"
android:background="#drawable/toast" >
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_gravity="fill_horizontal"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/someotherview"
android:layout_alignBottom="#+id/someotherview"
android:layout_alignLeft="#+id/someotherview"
android:text=""
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
</RelativeLayout>
I have tried virtually everything starting from android:gravity="fill" to android:ellipsize="marquee". Nothing seems to work. Does anyone know why?
Perhaps something like this would help you: http://www.androidviews.net/2012/12/autoscale-textview/
It re-sizes the textview (and the text) to fit in your other view.

RelativeLayout textviews overlapping

I have a rather simple ListView row:
<?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="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/tournament_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:textSize="25dp" />
<TextView
android:id="#+id/tournament_winner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:textSize="25dp" />
</RelativeLayout>
When the text of "#+id/tournament_name"is long - it overlaps with the one from "#+id/tournament_winner" and I don't understand why.
I tried using android:singleLine="false"to no avail. I also tried using android:inputType="textMultiLine"as the docu says android:singleLine="false" is deprecated but then I get the warning: Attribute android:inputType should not be used with <TextView>: Change element type to
<EditText> ? so no good here as well.
I also tried using android:ellipsize="end" but this doesn't work. I assume it is because the text in the left TextView ("#+id/tournament_name") is NOT long enough to fill up the full width of the ListView (which code is not sowing here).
I was sure that if I use android:layout_width="wrap_content"the two TextView fields shouldn't overlap.
Here is an example (see the second line):
Any further ideas how this could be fixed?
android:layout_toLeftOf="#id/tournament_winner" in First TextView.
Also set android:maxLines="1" and Fix width for tournament winner because when it gets long tournament name cant see...
row.xml
<?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="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/tournament_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#id/tournament_winner"
android:maxLines="1"
android:text="NAMEEEEEEEEEEEEEEEEEEEEEEEEEEE"
android:textSize="25dp" />
<TextView
android:id="#+id/tournament_winner"
android:layout_width="wrap_content" android:layout_marginLeft="10dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="WINER"
android:textSize="25dp" />
</RelativeLayout>
Thank you very much for your answer - sorry it took me some time to respond. I ended up using your android:layout_toLeftOf="#+id/tournament_winner" but left the single line and the margin to the left unused, as the result seemed perfect to me (hope this is also the case for other devices).
One thing though - in the first text view (tournament_name) I had to use android:layout_toLeftOf="#+id/tournament_winner"and not android:layout_toLeftOf="#id/tournament_winner" - pay attention to the added +. For some reason I get an error using android:layout_toLeftOf="#id/tournament_winner": Error: No resource found that matches the given name... so it seems that it is possible and NEEDED to define the resource in the time of calling it because the system doesn't know it before it was defined.
<?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="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/tournament_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/tournament_winner"
android:layout_alignParentLeft="true"
android:textSize="25dp" />
<TextView
android:id="#+id/tournament_winner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:textSize="25dp" />
</RelativeLayout>
You can use single text view in place of two and simply display both strings in one text view !!

Android XML Error parsing XML: junk after document element

I am getting this error:
Multiple annotations found at this line:
- The markup in the document following the root element must be well-
formed.
- error: Error parsing XML: junk after document element
This is appearing on the second TextView in this xml file.
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/text1"
android:textSize="16sp"
android:textStyle="bold"
android:textColor="#FFFF00"
android:layout_width="fill_parent"
android:layout_height="fill_parent"></TextView>
<TextView android:id="#+id/text2"
android:textSize="12sp"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
></TextView>
<TextView android:id="#+id/text3"
android:typeface="sans"
android:textSize="14sp"
android:textStyle="italic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></TextView>
Any ideas on the mistake I am making?
All help is appreciated.
An XML document can only have 1 root element. You have 3 such elements. You should enclose your TextView elements inside a layout, such as a LinearLayout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- TextView elements here -->
</LinearLayout>
Remove the xmlns attribute on the first TextView element.
you should encapsule your elements in layouts, such as LinearLayout. You can look at a layout config file in existence.

What does open quote expected for "android:id" in XML?

'<?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"
android:background="#drawable/droid_background" >
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_horizontal"
android:text="#string/hello"
android:textColor="#FFFFFF"
android:textStyle="bold" />
<GridView
android:id=”#+id/videoGrdVw”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:numColumns=”auto_fit”
android:verticalSpacing=”5dip”
android:horizontalSpacing=”5dip”
android:columnWidth=”80dip”
android:stretchMode=”columnWidth”
android:gravity=”center”/>
</RelativeLayout>
You've got fancy quotes mixed in with regular plain old quotes - replace the ”s with "s and it should work.
It looks like there's a strange problem with the quotes that you've posted. Some of them are of a different type than the others - look at the ones in the GridView. I would try changing them to be the same as the quotes up above and see if that helps.

Categories

Resources