John Womar
John Womar

Reputation: 11

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>

Upvotes: 0

Views: 625

Answers (1)

WarrenFaith
WarrenFaith

Reputation: 57672

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.

Upvotes: 2

Related Questions