[英]android relative layout background crash
好吧,我有一個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">
並且my_shape_normal被定義為
<?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>
加載時會引發異常:RelativeLayout所在行中的android.view.InflateException。 如果刪除“ android:background”,則一切正常。 my_shape_normal有什么問題?
當我剪切並粘貼您的XML時,LogCat讀取:
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #6
<gradient> tag requires 'angle' attribute to be a multiple of 45
因此,我已更新您的形狀XML以反映此要求:
<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>
注意,我還將相同的padding
元素組合為shape
一個屬性。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.