I have the next problem: I use a lot the RelativeLayout, like the Android documentation is telling me to do. But, since few days, I don´t understand why, this is not working anymore:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#drawable/background"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="#+id/boton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Button" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/boton"
android:layout_centerHorizontal="true"
android:layout_marginTop="60dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000" />
</RelativeLayout>
This is my layout, very simple. So, according to this one, the textView should be BELOW the button, but, instead, it appears OVER the button!
.
Сan anyone explain me what happens?
EDIT: The problem is not when I try to run it on a device, the problem comes when I see it on the graphical layout of the ADT Plugin for Eclipse...
I try this code it's working properly.
If your side not working properly Try to Clean build your project and then Run.
If still having problem then Try this
android:layout_below="#+id/boton"
remove above line with this
android:layout_below="#id/boton"
Because "+" create new reference to R.java file
This may be the issue.
try by removing the below line from your code
android:layout_marginTop="60dp"
Take the '+' sign out of the TextView's layout_below attribute. The '+' tells it to deine a new id. Without the '+' it should refer to the existing one.
I think your issue is the drawable for the background, since I am not seeing an image in your preview.
Having this issue is giving you a build error so the preview doesn't show the layout in its current state (it reverts to the last sucessful build). Either remove that line and save to see the preview or check to make sure that you have an image in your drawables folder titled "background"
Try this, without the drawable to check if it is working for you:
<?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" >
<Button
android:id="#+id/boton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Button" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/boton"
android:layout_centerHorizontal="true"
android:layout_marginTop="60dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000" />
</RelativeLayout>
I am trying to run it, and now, I know what´s the problem.
When running the app in a terminal, it is working properly, the problems comes when I try to see it on the graphical layout on the ADT plugin on Eclipse! Anyone with the same problem??
Add </RelativeLayout> at the end of your relative layout to close it.
Related
I just started using android studio and I inserted a button and text field. In preview panel looks ok but when I run the app the layout it's different.
This is the xml code:
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="16dp"
android:paddingTop="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
tools:context="com.example.alexander.myapplication.MainActivity">
<TextView
android:id="#+id/message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
tools:ignore="HardcodedText" />
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
tools:layout_editor_absoluteX="119dp"
tools:layout_editor_absoluteY="222dp"
tools:ignore="HardcodedText,MissingConstraints"
android:onClick="buttonClicked"
/>
This is how it looks like
Thank you!
Look at the lines:
tools:layout_editor_absoluteX="119dp"
tools:layout_editor_absoluteY="222dp"
What they say is that you placed the button in an absolute position BUT only in the editor preview.
The button doesn't have real placement values when the app actually running (notice the "editor" prefix in the parameters name).
You need to define actual values in the editor.
Check out this guide on the Android developers site:
Build a Responsive UI with ConstraintLayout
I just solved the problem by setting the layout to RelativeLayout.
So out of the blue I've ran into this problem. This is the Gradle Build console output:
https://i.stack.imgur.com/YxvfR.png
I've checked some posts online (mostly SO). So far I've changed the buildToolsVersion (which it doesn't let me be lower than 25.0.0), did Clean Builds, Restarts, checked all XML files for problems.
Nothing solved it. Also I didn't find anything about the first few errors ("No resourse matches..."). I tried to change those files to delete those lines but 1)"They're not part of the project" 2)If I change in anyway there's another error.
I've also returned to previous builds of my code, which worked and somehow now they all show the same errors.
Can you point me in the right direction? I want to understand what's wrong and how can I solve this?
[UPDATE]
Here's the code for res\layout\abc_list_menu_item_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.view.menu.ListMenuItemView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="?attr/listPreferredItemHeightSmall">
<!-- Icon will be inserted here. -->
<!-- The title and summary have some gap between them, and this 'group' should be centered vertically. -->
<RelativeLayout
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="?attr/listPreferredItemPaddingLeft"
android:layout_marginRight="?attr/listPreferredItemPaddingRight"
android:duplicateParentState="true">
<TextView
android:id="#+id/scale"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:textAppearance="?attr/textAppearanceListItemSmall"
android:singleLine="true"
android:duplicateParentState="true"
android:ellipsize="marquee"
android:fadingEdge="horizontal" />
<TextView
android:id="#+id/shortcut"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/title"
android:layout_alignParentLeft="true"
android:textAppearance="?android:attr/textAppearanceSmall"
android:singleLine="true"
android:duplicateParentState="true" />
</RelativeLayout>
<!-- Checkbox, and/or radio button will be inserted here. -->
And this one's for res\layout\abc_popup_menu_item_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.view.menu.ListMenuItemView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="?attr/dropdownListPreferredItemHeight"
android:minWidth="196dip"
style="#style/RtlOverlay.Widget.AppCompat.PopupMenuItem">
<!-- Icon will be inserted here. -->
<!-- The title and summary have some gap between them, and this 'group' should be centered vertically. -->
<RelativeLayout
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:duplicateParentState="true"
style="#style/RtlOverlay.Widget.AppCompat.PopupMenuItem.InternalGroup">
<TextView
android:id="#+id/scale"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:textAppearance="?attr/textAppearanceLargePopupMenu"
android:singleLine="true"
android:duplicateParentState="true"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
style="#style/RtlOverlay.Widget.AppCompat.PopupMenuItem.Text" />
<TextView
android:id="#+id/shortcut"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/title"
android:textAppearance="?attr/textAppearanceSmallPopupMenu"
android:singleLine="true"
android:duplicateParentState="true"
style="#style/RtlOverlay.Widget.AppCompat.PopupMenuItem.Text" />
</RelativeLayout>
<ImageView
android:id="#+id/submenuarrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:scaleType="center"
android:visibility="gone" />
<!-- Checkbox, and/or radio button will be inserted here. -->
The difference of these two to the res\merged\debug\SAME_NAME is none other than an error on the line xmlns:android="http://schemas.android.com/apk/res/android"saying URI is not registered. Since both of these files were created automatically I have no idea what's going on. I've searched this last "URI not registered" error but all the solutions presented are so different and seem so specific to one's project that they don't seem to apply here. I tried using Build Variant "release" and then changing it back but nothing happened again.
This happens out of the blue for me as well. I'm paying attention as to why that happened, but the solution is to clear the build cache.
To execute the task, select View > Tool Windows > Terminal from the menu bar and use one of the following commands:
For Windows: gradlew cleanBuildCache
For Mac or Linux: ./gradlew cleanBuildCache
For future reference and related options, check out this link:
Clear the build cache
Now, I finally got this to work but have simply no idea why or how it started working. So I had this ListView in one of my layouts and I wanted to add another in other layout. For some reason, when I created the second it changed the IDs of the first (one of them was 'title').
I deleted both ListViews but the problem persisted. So when I realized that I had the ListView with a 'title' id I decided to do it again with the first IDs and now everything works.
Couple of questions:
Why did the second ListView changed the first's IDs? - I created a Layout for the ListViews and seperate adapters since I wanted to show them in different ways.
Why deleting the layouts and the adapters did not solve the issue at first?
Plus, I still have an issue which is related. When I press the 3dots on the Toolbar (overflow), the app crashes. It throws a NullPointerException at ListMenuItemView. When I go to one of the faulty files in the question it says that it Cannot find the declaration of android.support.v7.view.menu.ListMenuItemView... Any ideas on what's going on?
I facing the problem that, I cant add new image button to my XML file.I added my icons to Drawable, but It cannot show in image button. XML shows an error ImageButton class not found. How can I solve this ?
I got the following error in xml
The following classes could not be found:
- ImageButton (Change to android.widget.ImageButton, Fix Build Path, Edit XML)
Here is my xml
<?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:orientation="vertical" >
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="109dp"
android:src="#drawable/facebook" />
</RelativeLayout>
Why dont you try a simple button instead of image button. Here is a code i have on some of my buttons with image.
android:drawableTop="#drawable/three" : this is basically the image
android:background="#drawable/buttonstyles" : this is a style for the button. No need to use it. Or the other layout features i have.
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/button2"
android:layout_alignParentRight="true"
android:layout_marginRight="20dp"
android:background="#drawable/buttonstyles"
android:drawableTop="#drawable/three"
android:onClick="goToSettings"
android:text="Settings" />
I was using the interface builder and for some reason, it added this
tools:src="#drawable/ic_play_arrow_white_100dp"
Change it to this to make it work and display image in image button
android:src="#drawable/ic_play_arrow_white_100dp"
I had the same problem. My images were .ico and I had the same error message in the Graphical Layout tab in eclipse. I proved to transform the .ico images to .png images and then I deleted the .ico and I imported the .png to the project.
It was succesful.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="109dp"
android:src="#drawable/a" />
<ImageButton
android:id="#+id/imageButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="164dp"
android:src="#drawable/a" />
</RelativeLayout>
I think this not big issue. Your is right nothing wrong with you posted. In my eclipse it works fine.
First check images properly put in drawable folder with small letter naming convention. or if you only have it in /res/drawable-xhdpi/ please check this also. May use this background instead of src.
if you not not getting R cannot resolve with putting image in xml, then first Refresh project, if is not work then clean whole project, if this is also not work restart eclipse.
if you restart eclipse, then it not work, may be your project library not properly located.
Change extend Activity to extend AppCompatActivity in your Activity Class
You need to define the Button as ImageButton in java classes.
When I run my android application in Android version >=4 I got this out put(I didn't tested in android version 3):
When run the same application in android version 2.3 I got a bit different output:
You can see in second screenshot the image for about button is not visible. But when I try run the same application several times on 2.3 some times I got about image visible.Here is my 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" >
<include layout="#layout/actionbar_with_right_button" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:scrollbars="none" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:drawablePadding="#dimen/settings_text_view_drawable_padding"
android:drawableTop="#drawable/snooze_button"
android:gravity="center"
android:onClick="showRemainderSnoozeSettings"
android:padding="#dimen/settings_text_view_padding"
android:text="#string/snooze" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:drawablePadding="#dimen/settings_text_view_drawable_padding"
android:drawableTop="#drawable/help_button"
android:gravity="center"
android:onClick="showFaq"
android:padding="#dimen/settings_text_view_padding"
android:text="#string/help" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:drawablePadding="#dimen/settings_text_view_drawable_padding"
android:drawableTop="#drawable/about_button"
android:gravity="center"
android:onClick="showAbout"
android:padding="#dimen/settings_text_view_padding"
android:text="#string/about" />
</LinearLayout>
</ScrollView>
I didn't understand why this is happening.
Can anyone help me to solve this issue.
Edit :
One more important thing I forgot to mention when I changed android:drawableTop="#drawable/about_button" to android:drawableTop="#drawable/help_button" of about TextView. It worked perfectly. So it can be an issue of my about_button image. So I recreated the about image again and put in all drawable folder. Even after that also I didn't get any +ve result. This issue only in 2.3 or less.
Thanks
May this help you:
Seems like this is a bug with android, where sometimes the first image in the drawable folder doesn't get displayed.....
I had a similar bug - a particular drawable was not being displayed, no matter in what ImageView. So I Added a dummy image called aaaa.png to the drawable folder and problem was solved....
Okay, so this is starting to really annoy me. This error pops up in a very special, not very logical way.
Let me start out by saying that I have already looked at the other questions regarding this error, Google'd it too. As far as I can tell, most similar problems occur because people refer to a String resource or something else not within the same layout file, they misplace the '+' in '#id+' or something similar.
The problem I am having occurs in a layout .xml file with a RelativeLayout. This contains a TableLayout, two LinearLayouts containing some text and finally a ProgressBar. What I want is the progress bar to be aligned with the relative layout using android:layout_alignParentBottom="true" and then align the two linear layouts above the progress bar (the bottom linear layout aligning above the progress bar, the other aligning above the bottom linear layout).
It should be simple enough and looks as if it works, i.e. the graphic view shows the desired result. However, and here comes the problem, Eclipse gives me an error on the two linear layouts,
"Error: No resource found that matches the given name (at 'layout_above' with value '#id/LinearLayout_acc')."
and the same error for the other linear layout referring to the progress bar. I have more than triple checked that there are no typos (the id's also exist in packagename.R.java), and I have tried cleaning the project a dozen times.
I don't get the error when saving (and auto building), not until I decide to run the project. Another weird thing is that when I refer to the bottom linear layout from the progress bar instead of the top linear layout, I get no error!
My layout file:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/background_activity" >
<TableLayout
... />
<LinearLayout
android:id="#+id/LinearLayout_dist"
android:layout_above="#id/LinearLayout_acc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp" >
<TextView
... />
<TextView
... />
</LinearLayout>
<LinearLayout
android:id="#+id/LinearLayout_acc"
android:layout_above="#id/ProgressBar_statusScreen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true" >
<TextView
... />
<TextView
... />
</LinearLayout>
<ProgressBar
android:id="#+id/ProgressBar_statusScreen"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_margin="16dp" />
</RelativeLayout>
Please help, I have no idea what causes this error!
Edit with answers
Shrikant came with the solution of changing the order of appearance in the layout file so that elements reference only other elements already defined when the reference is read.
Also, as others have posted, changing #id/ to #+id/, even in a reference, does remove the error messages. As Marco W. wrote in this thread, the thing is you have to use #+id/ the first time each id is mentioned and then use #id/ afterwards, even though the first time may not be a definition.
I made most of the design and set the referred id's in Eclipse's graphical editor, so code that resulted in an error message was automatically inserted. Maybe this is a bug in Eclipse.
change
#id/LinearLayout_acc
to
#+id/LinearLayout_acc
Please check the below code
<?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/ic_launcher" >
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:id="#+id/LinearLayout_dist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/LinearLayout_acc"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="FIRST" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SECOND" />
</LinearLayout>
<LinearLayout
android:id="#+id/LinearLayout_acc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/ProgressBar_statusScreen"
android:layout_centerHorizontal="true" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="THIRD" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="FOURTH" />
</LinearLayout>
<ProgressBar
android:id="#+id/ProgressBar_statusScreen"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_margin="16dp" />
</RelativeLayout>
Also check the following link.
It says that android:layout_below="#id/myTextView" won't recognise an element with id "myTextView" if it is written after the element you're using it in.
Change every id #id to #+id, no matter when it's defining or referencing an id. With this, you won't get
Android xml error: “No resource found that matches the given name” with RelativeLayout (#id/LinearLayout_acc, #id/ProgressBar_statusScreen).
<LinearLayout
android:id="#+id/LinearLayout_dist"
android:layout_above="#+id/LinearLayout_acc" <--- here might be a problem you forgot + sign
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp" >