Relative layout error aginst google api7 build - android

I'm trying to display the device's position on a map. i got my app working but the map wouldn't display. I've done lots of reading on the common errors for this eg map api key. my phone is a samsung galaxy 2.1. i noticed that i was building against google api8. so i mess up a bit on a few things and had to delete the project and copy and paste the src files back into a new project. the new project is built against google api7 now.
the problem is that the main.xml file has an error in it. The only thing i can think of is that i've changed what the project is built against api7 instead of api8. any ideas?
error: Error: String types not allowed (at 'layout_width' with value 'match_parent').
[edit] the error is in the relativelayout tag
.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content" android:gravity="fill">
<com.google.android.maps.MapView
android:id="#+id/myGMap"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:enabled="true"
android:clickable="true"
android:apiKey="02wE28syQIHzpwXXa95CrtA1XJLU5segJgltvKQ"
/>
<EditText android:id="#+id/edittext1"
android:inputType="text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<Button android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="CLOSE"
android:layout_alignParentRight="true"
android:id="#+id/close" ></Button>
</RelativeLayout>

Yes, in api level 7 there is no xml attibute match_parent exist, instead you need to use fill_parent.

Related

Android TextView top image not rendering properly on 2.3

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....

Android layout compatibility

I have problem with my widget with target android-14. minSDKVersion is 7. Widget looks and work fine under 3.1-4.x but under 3.1 I have problem with displaying. When I change target in project.properties to target=android-7 I get error in my layout files:
android:layout_width="match_parent"
android:layout_height="match_parent"
error: Error: String types not allowed (at 'layout_width' with value 'match_parent').
I also have error in *.java files, R cannot be resolved to a variable.
I understand that errors but how can I change my code to work with all targets form 2.1.
Thanks for any help.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/myWidget"
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal">
<ImageView android:id="#+id/myWidgetBackground"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:scaleType="centerInside"/>
<ImageView android:id="#+id/item1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:scaleType="centerInside"/>
<ImageView android:id="#+id/item2"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:scaleType="centerInside"/>
</RelativeLayout>
match_parent replaced fill_parent with 2.2 (API 8) if I am not mistaken. So replace it with fill_parent and it should work on 2.1 devices, too.
As you have errors in your xml files, the class R can't be generated and this results in the error you received.

Android The following classes could not be found - EditText (Change to android.widget.EditText, Fix Build Path, Edit XML)

When trying to view the Graphical Layout view I am getting the following error:
The following classes could not be found - EditText (Change to
android.widget.EditText, Fix Build Path, Edit XML)
The app works fine and I can edit the XML without any problems. I just can't load the graphical layout view anymore. In the Main.java file there are no problems or errors importing the EditText widget from the Android library.
I'm using Eclipse Indigo Service Release 2. Got all the recent updates.
I'm also using the latest Android SDK Tools 20.0.1
Here is the source. I've tried the option to Source > Cleanup Document and Format just to make sure the XML was correct.
<?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/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="63dp"
android:text="#string/button1" />
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginTop="16dp"
android:ems="10"
android:inputType="" >
<requestFocus />
</EditText>
</RelativeLayout>
I managed to fix the problem.
I had to change
android:inputType=""
to
android:inputType="text"
The Graphical Layout view now works again.
this is because if you are using api 4.4W which is recently released for android wear
and Android wear doesnot support edittext
http://developer.android.com/training/building-wearables.html

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"

Android crashes when calling ImageButton

I have a crash (Application Stopped Unexpectedly) problem with this main.xml is a "HelloWorld" type project (while testing and learning features I need for my app) :
I isolated the ImageButton as an issue, but I can't isolate any of the parameters...
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageButton android:id="#+id/picture"
android:layout_width="240dip"
android:layout_height="180dip"
android:layout_gravity="center_horizontal"
android:src="#drawable/icon"
android:adjustViewBounds="true"
android:cropToPadding="true"
android:clickable="true"
android:scaleType="fitCenter" />
</LinearLayout>
icon.png exists in my resources...
I can see the preview in the Layout tab, even though the image is not centered on the button, but I read that it was normal.
The code below works fine (as a regular Button). I can also do the same as an ImageView.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button android:id="#+id/picture"
android:layout_width="240dip"
android:layout_height="180dip"
android:layout_gravity="center_horizontal" />
</LinearLayout>
I use Eclipse and the AVD, and all my learning is done on 2.1 (SDK level 7).
I can't test the app on an actual device yet as I don't have it yet.
Thanks in advance !
Oh bother !!
It seems that it was a java error in my MyApp.java, when I was trying to declare the event for the button. Case closed. Sorry.

Categories

Resources