开发者

Unable to achieve rounded ListView on Android 2.2

I have a custom 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> 

I apply it via code:

listView.setBackgroundResource(R.drawable.rounded_corner);

but I get the error:

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)

How can I diagnose this? The resource exists.


Look in the "caused by" part of the stacktrace: Binary XML file line #4 tag requires 'angle' attribute to be a multiple of 45


try writing this
corners android:radius="7dp"
instead of
corners android:bottomRightRadius="7dp" android:bottomLeftRadius="7dp" android:topLeftRadius="7dp" android:topRightRadius="7dp"
Put this .xml file in drawable folder, and try using
listView.setBackgroundDrawable(drawable rounded_corner.xml);


Heres how I added rounded border around my list

<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>

This created a simple white border around my list with round edges. The padding in the listview was put to give a bit space or will look awkward when rows are added.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜