Im trying to relate widgets , I write the code as bellow:
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="90dp"
android:background="#drawable/ad1"
android:orientation="horizontal" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/ad1"
android:orientation="horizontal"
android:layout_toStartOf="#id/bt_menu" > // here there is error !!!!
<EditText
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:hint="Menu "
android:inputType="textVisiblePassword"/>
</RelativeLayout>
<ImageButton
android:id="#+id/bt_menu"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#android:color/transparent"
android:scaleType="fitCenter"
android:src="#drawable/menu5"
android:onClick="menu_onclick"/>
</RelativeLayout>
I have an error in this line:
android:layout_toStartOf="#id/bt_menu"
The error is : no resource found that matches the given name (at 'layout_toStartOf' with value '#id/bt_menu')
Can anyone help me please !!!!
Thank you in advance .. Fadel.
Change it to
android:layout_toStartOf="#+id/bt_menu" >
Add the "+"
If it is before the layout you are referencing then Eclipse doesn't seem to know about it until it has been saved. You should be able to change it back to how you have it after you have run it once. But I don't know that it will hurt anything to leave it. I do this if I use a property such as layout_below but put it before the View I want it to be relative to or something similar but I just leave it.
There may be a better way to handle this witin Eclipse, or whatever editor you are using, but AFAIK, this is the simplest and I don't know of any undesirable effects from it.
In my opition, is not the best way to use "#+id/" twice. You can receive errors of your R.java file. The problem you got is, that you use the id before you set it.
Solution:
Define id first by
android:layout_toStartOf="#+id/bt_menu"
Use id
android:id="#id/bt_menu"
Related
I've used toLeftOf many times before but it suddenly stopped working. I tried:
android:layout_toLeftOf="#id/spacer"
Here is the view:
<View
android:id="#+id/spacer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginLeft="#dimen/center_margin"
android:layout_marginStart="#dimen/center_margin"
android:layout_marginRight="#dimen/center_margin"
android:layout_marginEnd="#dimen/center_margin" />
And it gave me the errors:
Error:(16, 34) No resource found that matches the given name (at 'layout_toLeftOf' with value '#id/spacer').
Error:(17, 35) No resource found that matches the given name (at 'layout_toStartOf' with value '#id/spacer').
It works at other points in the app but for some reason it doesn't work here. Anyone know whats wrong?
Edit - Yes it is in a RelativeLayout. Here is a condensed version:
<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"
android:screenOrientation="portrait"
android:fitsSystemWindows="true"
android:focusableInTouchMode="true" >
<TextView
android:id="#+id/txt1" />
<View
android:id="#+id/spacer" />
<TextView
android:id="#+id/txt2" />
</RelativeLayout>
Upon further review I figured out the issue is I was trying to reference the View before it was made. I fixed this by changing #id/spacer to #+id/spacer
A bit late, but maybe still helpful for others. Took me 1 hour to find out my issue.
Non working example:
<TextView
android:id="#+id/firstview"
android:layout_toRightOf="#id/secondview"/>
<TextView
android:id="#+id/secondview"/>
Working example
<TextView
android:id="#+id/firstview"
android:layout_toRightOf="#+id/secondview"/>
<TextView
android:id="#+id/secondview"/>
Not the sign "+" being the only difference.
If you reference a view which is defined after the view you put the reference in, you need to use a +
Write the layout which is used as refrence, then the layout you want to put relative to that layout...
It's like trying to use variable before it was declared in the same class file.
You cannot reference a property that is not found in your respective ViewGroup. In this case you are trying to access properties that are specific to RelativeLayout. You cannot access these kinds of properties UNLESS your encapsulating view is in fact a RelativeLayout.
Note that this applies to the Parent layout that the view is encapsulated in.
This is driving me mad. My project compiled fine a moment ago. I made some minor change somewhere else, and now I'm getting this error. Here's the error message in full:
no resource found that matches the given name (at 'layout_above' with value '#id/blank_view").
Here's my XML file where the error is occurring:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageButton
android:id="#+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="#dimen/margin_right"
android:layout_above="#id/blank_view"
android:src="#drawable/button" />
<View
android:id="#+id/blank_view"
android:layout_width="match_parent"
android:layout_height="#dimen/margin_bottom"
android:layout_alignParentBottom="true" />
</RelativeLayout>
How in the hell could it be failing to find a resource with the name "#id/blank_view" when that resource is just below it in the file?
Btw, the reason I have my layout like this is that I want the ImageButton to be aligned to the bottom of my relative layout, but offset up by a margin. For some reason, those two attributes (layout_alignParentBottom and layout_marginBottom) don't mix well in the same view.
I should also point out that this happened earlier as well, but I just removed the reference that was giving AndroidStudio such a problem, rather than trying to fix it. This, however, is too important to wave away like that.
This happens because the xml is parsed in a linear fashion and the views/objects created in a top to bottom order. So your xml tells the view builder to put your ImageButton above an item that does not exist yet.
Just move it below the blank view and the error should go away.
Try to add the property to your view:
<view
android:id="#+id/blank_view"
android:layout_width="match_parent"
android:layout_height="#dimen/margin_bottom"
android:layout_alignParentBottom="true"
android:layout_below="#id/btn"
/>
And remove:
android:layout_above="#id/blank_view"
I am creating a button in my XML and here is the creation parameters
<Button android:id="#+id/btn2"
---> android:layout_width="wrap_content" <----
android:layout_height="wrap_content"
android:text="#string/PNR"
/>
I am getting and error in the line indicated saying :
" Element type "Button" must be followed by either attribute specifications, ">" or "/>" "
Not only in button id I try to create TextView or so then also same error comes and at same place.
I have checked earlier posts but they said that the tags were not closed and did not worked for me.
Please suggest me, what to do? Here is the full code :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button android:id="#+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/PNR"
/>
</LinearLayout>
Try cleaning your project
Project --> Clean... then choose your project
Sometimes Eclipse doesn't pick up changes to your xml. When you get goofy errors like this always try cleaning first. Sometimes you will get ClassCastException in Java code when running right after changing something in xml like
cannot cast Button to EditText
or something similar that won't make sense. This is also a good time to clean your project.
I would also recommend getting rid of whitespace within elements because I have had trouble with that as well (especially on older versions of Eclipse) plus I think it looks cleaner. So I would change your <Button... to
<Button android:id="#+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/PNR"/> <!-- just moved your end tag to this line -->
Let me first explain what my Androïd application is made of :
- a class extended from an Activity. In the OnCreate member of my class, I try to access a TextView described in my main.xml file by using
"MyTextView=(TextView)findViewById(R.id.myTextView);".
- an xml file where the TextView is described as follows :
<TextView
android:name="#+id/myTextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/another TextView"/>
In the R.java file, I can see that my TextView is registered.
My problem is that, when I try to get a handle on the TextView with the findViewById function, I get a null pointer.
It seems a mystery to me because I wrote another application where I was able to access TextViews. And I can't see any difference beetween both applications!!!
Hello,
Here is my complete layout file :
<TextView
android:name="#+id/Titre"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Application GPS :"/>
<TextView
android:name="#+id/NombreMaxSatellites"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<TextView
android:name="#+id/NombreSatellites"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello Android from NetBeans"/>
<TextView
android:name="#+id/TempsAcquisition"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello Android from NetBeans"/>
<EditText
android:name="#+id/Texte"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Le texte"/>
<Button android:id="#+id/BoutonTexte"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="130dip"
android:layout_marginTop="10dip"
android:text="Terminer"/>
I can access the Button but neither the TextView nor the EditText.
Any idea?
I am sure there are some errors in the layout, due to which your changes for layout were not saved. And then it is not reflecting in R.Java. Look for any red marks in your layout. Resolve the errors before your proceed, then it should work fine. Post your complete layout file.
Make sure that any calls to findViewById() occur after setting the layout with setContentView().
A good practice is to call setContentView() as the first line in your onCreate() method.
Make sure about 2 things
the ID of your textview is not repeated in the same layout
make sure that you are setting the content view (setContentView()) to the correct layout.
The problem is id is assigned to name android:name="#+id/Titre", it should be android:id="#+id/Titre".
For some reason, whenever I scroll through my list of items, the background inside my listview disappears and reappears giving rise to a "flicker" effect which I don't really want. I've tried the suggestion at: How to make a ListView transparent in Android? but it doesn't work for some reason. Any suggestions?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/screenLayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/background"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:background="#color/title_background"
android:text="#string/whatsnew_title"
>
</TextView>
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
</ListView>
</LinearLayout>
Did you include android:cacheColorHint="#00000000"? It's the most important part of the proposed fix. I've just tried your code (obviously not an exact reproduction, as you're using references to project-specific resources) with it, and it seems to work.
This post on the Android Developers blog should be of your interest.
This can also be achieved from Java (code) side: listView.setCacheColorHint(Color.TRANSPARENT);
Check your theme.xml for <item name="android:windowBackground">#null</item>. If you have it - remove it. I think one of the popular resources gives this line as example (that's how I got mine).