Nick
Nick

Reputation: 3435

android relative layout background crash

Well' I have a RelativeLayout

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:clickable="true"
    android:background="@drawable/my_shape_normal"
    android:onClick="startTestTillError">

and my_shape_normal is defined as

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
    android:startColor="#FFFFFF00"
    android:endColor="#80FFFFFF"
    android:angle="120"/>
<padding android:left="7dp"
    android:top="7dp"
    android:right="7dp"
    android:bottom="7dp" />
<corners android:radius="8dp" />
</shape>

On loading an exception is raised: android.view.InflateException at the RelativeLayout's line. If I remove "android:background", everything works perfect. What's wrong with my_shape_normal?

Upvotes: 3

Views: 7863

Answers (2)

josedlujan
josedlujan

Reputation: 5600

You have to use in the angle multiples of 45, example:

45, 90, 135, 180, 225, 270, 315, 360

Upvotes: 5

Sam
Sam

Reputation: 86948

When I cut & paste your XML my LogCat reads:

Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #6
    <gradient> tag requires 'angle' attribute to be a multiple of 45

So I've updated your shape XML to reflect this requirement:

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle"
    android:padding="7dp" >

    <gradient
        android:angle="135"
        android:endColor="#80FFFFFF"
        android:startColor="#FFFFFF00" />

    <corners android:radius="8dp" />

</shape>

Notice I also combined the identical padding elements into one attribute in shape.

Upvotes: 11

Related Questions