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.
Related
I am Developing an application that consists of a gauge view. I found code from here https://github.com/CodeAndMagic/GaugeView
I am getting an error of No resource identifier found forattribute'showOuterShadow' in package
'org.codeandmagic.android.gauge.demo. I added the library in the java build path of the project but it was still occurring please help me to solve this this is my xml code:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:gauge="http://schemas.android.com/apk/res/org.codeandmagic.android.gauge.demo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
android:background="#drawable/background"
android:padding="20dp" >
<org.codeandmagic.android.gauge.GaugeView
android:id="#+id/gauge_view1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<org.codeandmagic.android.gauge.GaugeView <!--Error occurring here-->
android:id="#+id/gauge_view2"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_marginTop="10dp"
gauge:showOuterShadow="true"
gauge:showOuterRim="false"
gauge:showNeedle="false"
gauge:showRanges="false"
gauge:showText="true"
gauge:textUnit="%" />
</LinearLayout>
This is so ridiculous to answer my own question:
i didn't add the library in my android project that is
YOUR PROJECT->RIGHTCLICK->POPERTIES->ANDROID->CLICK "ADD"->SELECT LIBRARY->CLICK "APPLY"->CLICK "OK"->RUN YOUR PROJECT
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....
I'm running Android lint in eclipse and get a error:
Wrong orientation? No orientation specified, and the default is
horizontal, yet this layout has multiple children where at least one
has layout_width="match_parent"
Issue: Checks that LinearLayouts with multiple children set the
orientation Id: Orientation
And this is the error code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="#dimen/cell_height_1_of_3" >
<ImageView
android:id="#+id/item_cover"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="left"
android:layout_marginLeft="8dp"
android:scaleType="fitCenter"
android:src="#drawable/doc_item_icon" />
<ImageView
android:layout_width="fill_parent"
android:layout_height="#dimen/cell_height_1_of_3"
android:background="#0000"
android:padding="5dp"
android:scaleType="centerInside"
android:visibility="gone" />
<TextView
android:id="#+id/item_title"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:ellipsize="end"
android:gravity="center"
android:maxLines="1"
android:text="Add new"
android:textColor="#color/office_color"
android:textSize="#dimen/textview_small_size" />
</LinearLayout>
What does it mean? What will happen if I ignored this lint error?
Android Lint is a new tool introduced in ADT 16 (and Tools 16) which scans Android project sources for potential bugs.
http://developer.android.com/tools/help/lint.html.
You have to specify orientation for your layout.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:orientation="vertical" //specify vertical or horizontal depending on your need
android:layout_height="#dimen/cell_height_1_of_3" >
http://tools.android.com/tips/lint-checks. list of the checks performed by lint.
If you didn't specify orientation in the LinearLayout the 2 ImageViews and the TextView will be rendered beside each other
android:orientation="horizontal"
will be assumed
If you want them to be rendered below each other then use
android:orientation="vertical"
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.
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.