我有一个自定义drawable rounded_corner.xml:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:startColor="#FFFFFF" android:endColor="#FFFFFF"
android:angle="90"/>
<corners android:bottomRightRadius="7dp" android:bottomLeftRadius="7dp"
android:topLeftRadius="7dp" android:topRightRadius="7dp"/>
</shape>
我通过代码申请:
listView.setBackgroundResource(R.drawable.rounded_corner);
但是我收到了错误:
5-09 20:39:17.434: ERROR/AndroidRuntime(1299): FATAL EXCEPTION: main
05-09 20:39:17.434: ERROR/AndroidRuntime(1299): java.lang.RuntimeException: Unable to start activity ComponentInfo{org.stocktwits.activity/org.stocktwits.activity.WatchlistActivity}: android.content.res.Resources$NotFoundException: File res/drawable-hdpi/rounded_corner.xml from drawable resource ID #0x7f02000d
05-09 20:39:17.434: ERROR/AndroidRuntime(1299): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
05-09 20:39:17.434: ERROR/AndroidRuntime(1299): at android.app.ActivityThread.startActivityNow(ActivityThread.java:2503)
05-09 20:39:17.434: ERROR/AndroidRuntime(1299): at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
05-09 20:39:17.434: ERROR/AndroidRuntime(1299): at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
05-09 20:39:17.434: ERROR/AndroidRuntime(1299): at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:651)
05-09 20:39:17.434: ERROR/AndroidRuntime(1299): at android.widget.TabHost.setCurrentTab(TabHost.java:323)
05-09 20:39:17.434: ERROR/AndroidRuntime(1299): at android.widget.TabHost$2.onTabSelectionChanged(TabHost.java:129)
05-09 20:39:17.434: ERROR/AndroidRuntime(1299): at android.widget.TabWidget$TabClickListener.onClick(TabWidget.java:453)
05-09 20:39:17.434: ERROR/AndroidRuntime(1299): at android.view.View.performClick(View.java:2408)
05-09 20:39:17.434: ERROR/AndroidRuntime(1299): at android.view.View$PerformClick.run(View.java:8816)
05-09 20:39:17.434: ERROR/AndroidRuntime(1299): at android.os.Handler.handleCallback(Handler.java:587)
05-09 20:39:17.434: ERROR/AndroidRuntime(1299): at android.os.Handler.dispatchMessage(Handler.java:92)
05-09 20:39:17.434: ERROR/AndroidRuntime(1299): at android.os.Looper.loop(Looper.java:123)
05-09 20:39:17.434: ERROR/AndroidRuntime(1299): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-09 20:39:17.434: ERROR/AndroidRuntime(1299): at java.lang.reflect.Method.invokeNative(Native Method)
05-09 20:39:17.434: ERROR/AndroidRuntime(1299): at java.lang.reflect.Method.invoke(Method.java:521)
05-09 20:39:17.434: ERROR/AndroidRuntime(1299): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-09 20:39:17.434: ERROR/AndroidRuntime(1299): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-09 20:39:17.434: ERROR/AndroidRuntime(1299): at dalvik.system.NativeStart.main(Native Method)
05-09 20:39:17.434: ERROR/AndroidRuntime(1299): Caused by: android.content.res.Resources$NotFoundException: File res/drawable-hdpi/rounded_corner.xml from drawable resource ID #0x7f02000d
05-09 20:39:17.434: ERROR/AndroidRuntime(1299): at android.content.res.Resources.loadDrawable(Resources.java:1697)
05-09 20:39:17.434: ERROR/AndroidRuntime(1299): at android.content.res.Resources.getDrawable(Resources.java:581)
05-09 20:39:17.434: ERROR/AndroidRuntime(1299): at android.view.View.setBackgroundResource(View.java:7393)
05-09 20:39:17.434: ERROR/AndroidRuntime(1299): at org.stocktwits.activity.WatchlistActivity.setupUI(WatchlistActivity.java:184)
05-09 20:39:17.434: ERROR/AndroidRuntime(1299): at org.stocktwits.activity.WatchlistActivity.onCreate(WatchlistActivity.java:127)
05-09 20:39:17.434: ERROR/AndroidRuntime(1299): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-09 20:39:17.434: ERROR/AndroidRuntime(1299): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
05-09 20:39:17.434: ERROR/AndroidRuntime(1299): ... 18 more
05-09 20:39:17.434: ERROR/AndroidRuntime(1299): Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #4<gradient> tag requires 'angle' attribute to be a multiple of 45
05-09 20:39:17.434: ERROR/AndroidRuntime(1299): at android.graphics.drawable.GradientDrawable.inflate(GradientDrawable.java:678)
05-09 20:39:17.434: ERROR/AndroidRuntime(1299): at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:788)
05-09 20:39:17.434: ERROR/AndroidRuntime(1299): at android.graphics.drawable.Drawable.createFromXml(Drawable.java:729)
05-09 20:39:17.434: ERROR/AndroidRuntime(1299): at android.content.res.Resources.loadDrawable(Resources.java:1694)
我该如何诊断?资源存在。
答案 0 :(得分:0)
查看堆栈跟踪的“由...”部分: 二进制XML文件行#4标记要求'angle'属性为45的倍数
答案 1 :(得分:0)
试着写这个
角落android:radius =“7dp”
而不是
角落android:bottomRightRadius =“7dp”android:bottomLeftRadius =“7dp”
android:topLeftRadius =“7dp”android:topRightRadius =“7dp”
将此.xml文件放在drawable文件夹中,然后尝试使用
listView.setBackgroundDrawable(drawable rounded_corner.xml);
答案 2 :(得分:0)
下面是我如何在列表中添加圆形边框
<ListView android:layout_width="fill_parent" android:id="@id/android:list"
android:layout_height="0dip" android:layout_weight="1.0"
android:background="@drawable/app_user_list_drawable" android:fadeScrollbars="true"
android:descendantFocusability="afterDescendants" android:layout_margin="10dip"
android:listSelector="@android:color/transparent" android:paddingLeft="10dip"
android:paddingRight="10dip" android:divider="#7D7D7D" android:dividerHeight="1px"/>
app_user_list_drawable.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="10dip"/>
<padding android:left="0dip" android:top="1dip" android:right="0dip"
android:bottom="1dip"/>
<stroke android:width="1dip" android:color="#7D7D7D"/>
</shape>
这会在我的列表周围创建一个带有圆边的简单白色边框。列表视图中的填充被赋予了一些空间,或者在添加行时看起来很尴尬。