RelativeLayout - Couldnt resolve resource - android

I have a relative layout which works fine at runtime but in the Eclipse graphical layout designer I receive the exception
Couldn't resolve resource #id/imgSessionOutcome_Product1_Icon
The resource of the imageview is defined and is before the references to it, so I can't quite see what the issue is ? The exception is listed twice so both references to it fail.
I've saved/cleaned project to make sure resources rebuilt, still same error.
Eclipse Version: Helios Service Release 2 running on OSX with latest updates etc.
<RelativeLayout
android:id="#+id/lySessionOutcome_Product1"
android:layout_width="match_parent"
android:layout_height="55dip"
android:layout_marginLeft="10dip"
android:layout_marginRight="5dip"
android:orientation="vertical"
android:visibility="gone">
<ImageView
android:id="#+id/imgSessionOutcome_Product1_Icon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_marginRight="10dip"
android:src="#drawable/gr_bag_bc" />
<TextView
android:id="#+id/tvSessionOutcome_Product1_Description"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_toRightOf="#id/imgSessionOutcome_Product1_Icon"
android:ellipsize="marquee"
android:singleLine="false"
android:text="Description" />
<TextView
android:id="#+id/tvSessionOutcome_Product1_Type"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#id/tvSessionOutcome_Product1_Description"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_alignWithParentIfMissing="true"
android:layout_toRightOf="#id/imgSessionOutcome_Product1_Icon"
android:gravity="center_vertical"
android:text="Product type"
android:textAppearance="#style/largeBlack" />
</RelativeLayout>

try using
android:layout_toRightOf="#+id/imgSessionOutcome_Product1_Icon"
Well I answered this long time ago I didn't knew why it works then and I am still not sure but based on my observation I think using + sign instead creates a temporary reference to the view so that we can view it in Android layout editor, actual anchor view gets picked at runtime only.
If you wont use the + sign it works fine at runtime as stated in the question itself.
Please correct me if I am wrong.

Related

How to port RelativeLayout from Android source code?

Background
I have a card-like UI on my app, which uses a RelativeLayout.
The problem
Recently I've discovered that on at least one device ( or rom, or andorid version), when I switch to an RTL language (such as Hebrew), everything got messed up.
This has happened only on LG G2 with Android V4.2.2 .
Here's what I see:
If you compare it to the screenshots of the app, you can see this is not how it should look like.
That's even though on all Android devices that I've checked, and on all emulators, I've never seen it (even when switching to Hebrew).
What I've tried
I've tried to fix it by using a GridLayout instead, but that wasn't working well (link here).
I've also tried to use a LinearLayout, but considering there might be issues with it, I've used LinearLayoutCompat instead. It works, but it's not recommended to use so many.
Another thing I've tried is to port the RelativeLayout of Android source code, but this gives me a lot of warnings and errors that are quite hard to handle.
Here's the original XML of the layout, BTW (I've removed the irrelevant stuff, to make it shorter) :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="afterDescendants" >
<ImageView
android:id="#+id/appIconImageView"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:adjustViewBounds="true"
android:src="#android:drawable/sym_def_app_icon" />
<LinearLayout
android:id="#+id/appDetailsContainer"
android:layout_width="0px"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toEndOf="#+id/appIconImageView"
android:layout_toLeftOf="#+id/overflowView"
android:layout_toRightOf="#+id/appIconImageView"
android:layout_toStartOf="#+id/overflowView"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:text="label" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="description" />
</LinearLayout>
<ImageView
android:id="#+id/overflowView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="#android:drawable/sym_def_app_icon" />
<ImageView
android:id="#+id/isSystemAppImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:src="#android:drawable/sym_def_app_icon" />
</RelativeLayout>
The question
As I use RelativeLayout, how can I port the code from the official source code of Android?
Is there maybe a library that does it?

Cannot resolve symbol 'container' - Android Studio

I just created a new projet, building some layouts, writing some code. Everything was fine except I got this error as shown in the picture below.
I tried to remove and type it again and when typing 'R.id.', there was no 'container' showing up in the list. So that means theres no problem with my R file, just that the 'container' word lost somewhere.
Those code above are actually default code in onCreate() method in your main activity everytime you create a new project in Android Studio. (I actually tried to create a new project to compare and yes it's the same, and without error as it's brand new.).
All I did was comment out the if statement block so the error goes away, and the application has run just fine on the emulator. I just don't know why I got that problem and how I can handle it as I may need to do that in the future. Thank you!
Edit after #Raghunandan has mentioned: Below is my xml.
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/provide_information"
android:id="#+id/provideInfoButton"
android:layout_alignParentTop="true" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/take_picture"
android:id="#+id/takePictureButton"
android:layout_below="#+id/provideInfoButton"
android:layout_alignParentLeft="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView"
android:layout_below="#+id/takePictureButton"
android:layout_centerHorizontal="true"
android:layout_marginTop="28dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/classNameTextView"
android:layout_above="#+id/personNametextView2"
android:layout_centerHorizontal="true"
android:layout_marginBottom="44dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_marginBottom="38dp"
android:layout_above="#+id/emailTextView"
android:layout_alignLeft="#+id/emailTextView"
android:id="#+id/personNameTextView" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/emailTextView"
android:layout_alignParentBottom="true"
android:layout_alignLeft="#+id/classNameTextView"
android:layout_marginBottom="82dp" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/send_button"
android:id="#+id/sendButton"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
The reason is that I changed the root layout to RelativeLayout (the default of Android Studio was FrameLayout which has an id of "container"). My bad :). Thanks for mentioning about posting the xml file. I have not noticed that as I'm not as familiar with Android Studio as with Eclipse yet.

Empty Region - Android XML Layout and Mac OS X 10.7

I've been using the ADT release from developers.android.com that comes with SDK and Eclipse in one package. I have some code that gives me a Empty Region exception upon drawing the XML file in the graphical layout tab.
Exception raised during rendering: Empty region! Exception details are
logged in Window > Show View > Error Log
java.lang.IllegalArgumentException: Empty region!
at javax.imageio.ImageReader.computeRegions(ImageReader.java:2689)
at com.sun.imageio.plugins.wbmp.WBMPImageReader.read(WBMPImageReader.java:184)
at javax.imageio.ImageIO.read(ImageIO.java:1422)
at javax.imageio.ImageIO.read(ImageIO.java:1282)
at android.graphics.Bitmap_Delegate.createBitmap(Bitmap_Delegate.java:96)
at com.android.layoutlib.bridge.impl.ResourceHelper.getDrawable(ResourceHelper.java:233)
at com.android.layoutlib.bridge.bars.CustomBar.loadIcon(CustomBar.java:196)
at com.android.layoutlib.bridge.bars.CustomBar.loadIconById(CustomBar.java:188)
at com.android.layoutlib.bridge.bars.CustomBar.loadIconById(CustomBar.java:155)
at com.android.layoutlib.bridge.bars.FakeActionBar.(FakeActionBar.java:38)
This came on suddenly and shows a null pointer exception on Windows version of eclipse with the SDK.
I've checked for all images, as someone somewhere said something about corrupted images. Programs can view them just fine. I've fixed the project settings and reloaded eclipse, failed to resolve.
<com.demortes.controller.DualJoystickView
android:id="#+id/dualjoystickView"
android:layout_gravity="center_horizontal"
android:layout_width="fill_parent" android:layout_height="175dp"
android:layout_marginLeft="10dp" android:layout_marginRight="10dp"/>
<Button
android:id="#+id/button_A"
android:layout_width="90dp"
android:text="#string/a_button"
android:textSize="24sp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginRight="10dp" />
<Button
android:id="#+id/button_B"
android:text="#string/b_button"
android:textSize="24sp"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" >
<Button
android:id="#+id/button_Y"
android:text="#string/y_button"
android:textSize="24sp"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:layout_marginRight="10dp" />
<Button
android:id="#+id/button_X"
android:text="#string/x_button"
android:textSize="24sp"
android:layout_width="90dp"
android:layout_height="wrap_content" />
</LinearLayout>
There's my XML file.
Now here's where it gets weird. When I switch the API from 17 to 8 in the graphical layout tab, it draws it... but incorrectly. It's completely strange to me.
Any insight you can think of is greatly appreciated! TIA.
check Manifest.xml like this
<application
android:label="#string/app_name"
android:icon="#drawable/logo"/>
make sure "drawable_hdpi" "drawable_ldpi" "drawable_mdpi" have file logo.png and the image resolution is correct.

RelativeLayout not working properly Android

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.

How to properly configure AdMob using IntelliJ IDEA?

I'm trying to incorporate AdMob into my Android application. I'm using IntelliJ IDEA for development and I cannot seem to set my project up properly. At this point I've done the following:
Did all the preliminary steps necessary to download the AdMob SDK.
Followed the directions here, trying to augment them for IntelliJ IDEA. I've added a Single-Entry Module Library dependency to the AdMob SDK to my project.
It looks like the IDE has no problem recognizing the classes from the SDK if I try to use them in code. However, it fails to resolve them in XML. I have the following two errors:
Cannot resolve symbol 'AdActivity' when I set up the ad activity in AndroidManifest.xml the instructions call for.
Element com.google.ads.AdView is not allowed here when I try to add an ad view to a layout in the manner documented here.
Thank you very much in advance for your help. I hope I've been clear.
EDIT
A clarification based on Cristian's answer. It's true that the first error seems to not matter. However, the second error causes the project build to break with the following message:
.../res/layout/main.xml:7: error: Error parsing XML: unbound prefix
The XML in question is the following layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.google.ads.AdView android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="MY_AD_UNIT_ID"
ads:adSize="BANNER"
ads:loadAdOnCreate="true"/>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="123dp"
android:src="#drawable/logo"/>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:src="#drawable/cart"/>
<Button android:id="#+id/new_shopping_list"
android:layout_width="223dp"
android:layout_height="wrap_content"
android:layout_marginTop="90dp"
android:text="#string/new_shopping_list_btn"/>
<Button android:id="#+id/view_all_shopping_lists"
android:layout_width="223dp"
android:layout_height="wrap_content"
android:layout_below="#id/new_shopping_list"
android:text="#string/saved_shopping_lists_btn"/>
<ImageView android:id="#+id/copyright_notice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="7dp"
android:layout_marginRight="5dp"
android:src="#drawable/copyright"/>
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#id/copyright_notice"
android:layout_alignParentRight="true"
android:layout_marginBottom="5dp"
android:layout_marginRight="4dp"
android:src="#drawable/techsmart_logo"/>
<ImageButton android:id="#+id/user_guide"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="7dp"
android:layout_marginLeft="5dp"
android:src="#drawable/user_guide"/>
</RelativeLayout>
Do not worry about those errors. AdMob library is obfuscated, thus IntelliJ cannot read the correct names of the classes. However, your application will compile and run fine. This is how one of my projects looks like, and they work fine:
As you can see, there are other libraries like Pontiflex or AirPush that has the same problem.
With regards to your second problem, it seems you forget to add the XML NameSpace. This answer says that you must add this one:
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"

Categories

Resources