Android Layout Issue Using axml - In Xamarin - android

Can anyone see a problem with the code below?
The error is that the id Title is not being recognised as a valid id when I try to use it for alignment even though it is created above the reference in the hierarchy.
The warning sign says: The referenced resource does not exist.
<?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:minHeight="150dp"
android:background="#android:color/white"
android:orientation="horizontal">
<TextView
android:id="#+id/Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:lineSpacingExtra="3dp"
android:paddingLeft="10dp"
android:paddingTop="5dp"
android:textColor="#ffffff"
android:textStyle="bold"
android:background="#android:color/holo_green_light"
android:typeface="sans"
android:text="AAAAA"
android:layout_centerVertical="true" />
<TextView
android:id="#+id/Description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingTop="5dp"
android:textColor="#android:color/black"
android:textSize="11sp"
android:text="aaaaaaa"
android:layout_alignTop="#id/Title"
/>
</RelativeLayout>

Didn't see anything wrong with your axml file and it worked fine for me in Xamarin. No errors. Have you tried a clean build? Sometimes errors in other axml files cause errors in correct files. Try removing both textviews and recompiling. Maybe that will show any other errors.

Related

Android XML error while generating signed .apk file

I've not opened this particular project for about 3 months but when I tried to generate a signed .apk file, I get this one error only:
C:\app\src\main\res\layout\fragment_newanswers.xml:57: Error: The id "linearLayout2" is not defined anywhere. [UnknownId]
android:layout_alignTop="#+id/linearLayout2"
Here's my current code in that xml file:
<TextView
android:text="OptionView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/txtOptionTitle"
android:textSize="24sp"
android:textAlignment="center" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/txtOptionTitle"
android:layout_alignParentStart="false"
android:layout_alignParentBottom="false">
<!--
<TextView
android:text="QuestionView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/txtQuestionTitle"
android:textAlignment="center"
android:textSize="18sp" />
-->
<com.rokonoid.widget.ExpandableTextView
android:id="#+id/txtQuestionTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="18sp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.bozapro.circularsliderrange.CircularSliderRange
android:id="#+id/cirAns"
android:layout_width="wrap_content"
android:layout_height="343dp"
circular:start_angle="270"
circular:end_angle="300"
circular:start_thumb_size="0dp"
android:paddingLeft="75dp"
android:paddingRight="75dp" />
<TextView
android:text="5%"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/linearLayout2"
android:layout_centerHorizontal="true"
android:id="#+id/txtPercent"
android:textAlignment="center"
android:textSize="36sp"
android:layout_marginTop="150dp" />
</RelativeLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:text="Back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/btnQnsBack"
android:layout_weight="1" />
<Button
android:text="Next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/btnQnsNext"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
Funny thing is, it worked multiple times previously and I did not make any changes at all. I can also rebuild and clean build it without errors. Oddly, my backup versions which are Identical, generate this ONE same error for my 6 different xml files here:
Error:(5) Error: Suspicious namespace and prefix combination [NamespaceTypo]
It points to this line in each of the 6 files:
xmlns:app="http://schemas.android.com/tools"
My guess is I'm not calling something in the MainActivity (but that would not explain why it has always worked -with fully functioning .apk) Any thoughts?
Thanks heaps!
James
Remove this line
android:layout_alignTop="#+id/linearLayout2"
From
<TextView
android:text="5%"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/linearLayout2"
android:layout_centerHorizontal="true"
android:id="#+id/txtPercent"
android:textAlignment="center"
android:textSize="36sp"
android:layout_marginTop="150dp" />
As i see no layout with id linearLayout2 in your file above. Errors of such kind are not generated in the debug build but in the realease build.
As #Malik Ahhsan said, just remove the android:layout_alignTop="#+id/linearLayout2"

android:layout_below doesn't seem to work

Using Xamarin in Visual Studio 2015 I am trying to edit the Main.axml file. in the file I have the TextView item:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/relativeLayout1" >
<TextView
android:text="Search By Postal Code"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/PostalCodeSearchLabel"
android:layout_margin="10dp" />
<EditText
android:inputType="number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/PostalCodeSearchLabel"
android:id="#+id/zipCodeEntry"
android:layout_marginLeft="10dp"
android:layout_marginBottom="10dp"
android:width="165dp" />
<Button
android:id="#+id/ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/zipCodeEntry"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dp"
android:text="OK" />
</RelativeLayout>
But the lines "layout_below" shows as invalid and the item doesn't display properly. All the examples I've read show this as being a valid parameter but it doesn't work.
Why?
It seems to be a simple matter of saving my changes. When switching back to the designer after making changes in the source mode you have to save the changes before the designer will render properly.
You have to define the EditText after the view want it to go below.
<!-- Your view here -->
<EditText
android:inputType="number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/ZipCodeSearchLabel"
android:id="#+id/zipCodeEntry"
android:layout_marginLeft="10dp"
android:layout_marginBottom="10dp"
android:width="165dp" />
If you reference an element by id-#id/foo but the element comes after the reference in xml then it won't work

App shows no errors but crashes

I'm still fairly new to programming.
I'm working on a practice app and it crashes whenever I try to run it. I've tried moving the main body of the code to different app templates and it still crashes. I tried putting it in place of code in a working app and it fails. I'm sure it is something in the code and can't wait to find out what. Thank you all in advance for your help.
-Joseph
Here is my code;
<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="match_parent"
tools:ignore="contentDescription">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/goliath2"
android:scaleType="centerCrop"
android:id="#+id/imageGoliath"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, I'm Goliath."
android:textColor="#C62828"
android:textSize="36sp"
android:fontFamily="sans-serif-medium"
android:textStyle="bold"
android:id="#+id/ImGoliath"
android:layout_centerInParent="true"
android:layout_alignParentTop="true"
android:padding="12dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Don't be afraid, I don't bite..."
android:textSize="26sp"
android:fontFamily="sans-serif-medium"
android:textColor="#C62828"
android:id="#+id/afraid"
android:layout_below="#id/ImGoliath"
android:textStyle="bold|italic"
android:paddingLeft="12dp"
android:paddingBottom="18dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/unless"
android:text="Unless!"
android:textColor="#C62828"
android:textSize="52sp"
android:textStyle="bold"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="#id/afraid"
android:padding="24dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/Youreacricket"
android:text="YOU'RE A CRICKET!"
android:textColor="#C62828"
android:layout_alignParentBottom="true"
android:textSize="42sp"
android:textStyle="bold"
android:layout_centerInParent="true"
android:paddingTop="60dp"/>
It appears that my problem was likely an image file that was too large.
After replacing the image with the androidparty image I got during class the app ran fine.
Thank you all who tried to help.

Android XML error: no resource identifier found for attribute 'xmlns' in package 'android'

I know there are a hundred questions here just like mine, but none of them seem to suit my specific problem, so I am asking a new question. Just in case this is a repeat, I'm sorry.
So, I am building an app, and the layout is causing me a few problems.
This is my XML code : (it's not yet complete)
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/toosl"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="vertical"
android:xmlns="http://schemas.android.com/apk/res/android" >
<TextView
android:id="#+id/showNunmber"
android:layout_width="wrap_content"
android:layout_marginTop="15dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="number"
android:textSize="30sp"/>
<TextView
android:id="#+id/showAnswer"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="answer"
android:layout_marginTop="35dp"
android:layout_gravity="center"
android:textSize="25sp"/>
</LinearLayout>
The error that I'm getting is in the first line of the code
where it says "error: no resource identifier found for attribute 'xmlns' in package 'android'
I've gone over and over the code, I've tried to refresh/rebuild the project, I tried deleting that particular line, etc.. and nothing seems to solve it.
So, if anyone has some ideas?
Thanks!
Remove
android:xmlns="http://schemas.android.com/apk/res/android"
from your layout,i.e. use your layout as
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/toosl"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="vertical">
<TextView
android:id="#+id/showNunmber"
android:layout_width="wrap_content"
android:layout_marginTop="15dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="number"
android:textSize="30sp"/>
<TextView
android:id="#+id/showAnswer"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="answer"
android:layout_marginTop="35dp"
android:layout_gravity="center"
android:textSize="25sp"/>
</LinearLayout>
Replace it with this
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="vertical"
>
<TextView
android:id="#+id/showNunmber"
android:layout_width="wrap_content"
android:layout_marginTop="15dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="number"
android:textSize="30sp"/>
<TextView
android:id="#+id/showAnswer"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="answer"
android:layout_marginTop="35dp"
android:layout_gravity="center"
android:textSize="25sp"/>
</LinearLayout>
I found my mistake, it's in the last attribute of my first LinearLayout tag.
I should not have included that line at the bottom.
I removed that line and now its working.
Thank you!
if none of the above worked make sure you add this:
compile 'com.android.support:percent:23.1.1'
to your build.gradle

I Made A Background For my App, But Now It Won't Run

I just set up a background for this app I'm making, but now it won't run. It was working before I assigned the background. I was wondering if someone could help me with this. Maybe I'm supposed to have some java code with it as well?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/backgroundhdpi" >
<EditText
android:id="#+id/bill"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="100dp"
android:ems="10"
android:inputType="phone"
android:text="Enter Your Bill"
android:textSize="18dip" />
<Button
android:id="#+id/calculateTip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/bill"
android:layout_alignParentBottom="true"
android:layout_marginBottom="40dp"
android:layout_marginLeft="15dp"
android:text="Calculate" />
<TextView
android:id="#+id/tipOwed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/bill"
android:layout_centerHorizontal="true"
android:layout_marginBottom="123dp"
android:scrollHorizontally="false"
android:text="Time to Tip"
android:textColor="#2c6f37"
android:textSize="35dip"
android:textStyle="bold" />
</RelativeLayout>
As long as the background is in res/drawable it shouldn't cause any crashing issues. There is no Java that needs to be associated with setting a background that way. Is there an error in the logcat?
(I would leave this as a comment but I don't have enough rep to do so)

Categories

Resources