如何在通用图像加载器中加载布局作为中间图像

时间:2016-07-21 18:01:36

标签: android android-layout listview universal-image-loader

我正在查看动态高度的图像视图,我想在中心显示带有我的应用程序徽标的中间图像。由于高度是动态的,因此在中心处具有徽标的抽屉看起来会拉伸。我正在尝试向中间体添加布局,如下所示加载失败图像,

    options = new DisplayImageOptions.Builder()
            .showImageOnLoading(R.layout.popup)
            .showImageForEmptyUri(R.layout.popup)
            .showImageOnFail(R.layout.popup)
            .cacheInMemory(false).cacheOnDisk(true)
            .considerExifParams(true)
            .bitmapConfig(Bitmap.Config.RGB_565).build();

我收到以下错误,

07-21 23:23:58.039: E/AndroidRuntime(19886): FATAL EXCEPTION: main
07-21 23:23:58.039: E/AndroidRuntime(19886): android.content.res.Resources$NotFoundException: File res/layout/popup.xml from drawable resource ID #0x7f03000e
07-21 23:23:58.039: E/AndroidRuntime(19886):    at android.content.res.Resources.loadDrawable(Resources.java:1912)
07-21 23:23:58.039: E/AndroidRuntime(19886):    at android.content.res.Resources.getDrawable(Resources.java:657)
07-21 23:23:58.039: E/AndroidRuntime(19886):    at com.nostra13.universalimageloader.core.DisplayImageOptions.getImageOnLoading(DisplayImageOptions.java:134)
07-21 23:23:58.039: E/AndroidRuntime(19886):    at com.nostra13.universalimageloader.core.ImageLoader.displayImage(ImageLoader.java:257)
07-21 23:23:58.039: E/AndroidRuntime(19886):    at com.nostra13.universalimageloader.core.ImageLoader.displayImage(ImageLoader.java:365)
07-21 23:23:58.039: E/AndroidRuntime(19886):    at com.tm.updater.MainPage$ImageAdapter.getView(MainPage.java:746)
07-21 23:23:58.039: E/AndroidRuntime(19886):    at android.widget.AbsListView.obtainView(AbsListView.java:2340)
07-21 23:23:58.039: E/AndroidRuntime(19886):    at android.widget.ListView.measureHeightOfChildren(ListView.java:1250)
07-21 23:23:58.039: E/AndroidRuntime(19886):    at android.widget.ListView.onMeasure(ListView.java:1162)
07-21 23:23:58.039: E/AndroidRuntime(19886):    at android.view.View.measure(View.java:15264)
07-21 23:23:58.039: E/AndroidRuntime(19886):    at android.widget.RelativeLayout.measureChild(RelativeLayout.java:602)
07-21 23:23:58.039: E/AndroidRuntime(19886):    at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:415)
07-21 23:23:58.039: E/AndroidRuntime(19886):    at android.view.View.measure(View.java:15264)
07-21 23:23:58.039: E/AndroidRuntime(19886):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4918)
07-21 23:23:58.039: E/AndroidRuntime(19886):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
07-21 23:23:58.039: E/AndroidRuntime(19886):    at android.view.View.measure(View.java:15264)
07-21 23:23:58.039: E/AndroidRuntime(19886):    at android.widget.LinearLayout.measureVertical(LinearLayout.java:833)
07-21 23:23:58.039: E/AndroidRuntime(19886):    at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
07-21 23:23:58.039: E/AndroidRuntime(19886):    at android.view.View.measure(View.java:15264)
07-21 23:23:58.039: E/AndroidRuntime(19886):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4918)
07-21 23:23:58.039: E/AndroidRuntime(19886):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
07-21 23:23:58.039: E/AndroidRuntime(19886):    at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2161)
07-21 23:23:58.039: E/AndroidRuntime(19886):    at android.view.View.measure(View.java:15264)
07-21 23:23:58.039: E/AndroidRuntime(19886):    at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2150)
07-21 23:23:58.039: E/AndroidRuntime(19886):    at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1255)
07-21 23:23:58.039: E/AndroidRuntime(19886):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1448)
07-21 23:23:58.039: E/AndroidRuntime(19886):    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1140)
07-21 23:23:58.039: E/AndroidRuntime(19886):    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4726)
07-21 23:23:58.039: E/AndroidRuntime(19886):    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:747)
07-21 23:23:58.039: E/AndroidRuntime(19886):    at android.view.Choreographer.doCallbacks(Choreographer.java:567)
07-21 23:23:58.039: E/AndroidRuntime(19886):    at android.view.Choreographer.doFrame(Choreographer.java:536)
07-21 23:23:58.039: E/AndroidRuntime(19886):    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:733)
07-21 23:23:58.039: E/AndroidRuntime(19886):    at android.os.Handler.handleCallback(Handler.java:615)
07-21 23:23:58.039: E/AndroidRuntime(19886):    at android.os.Handler.dispatchMessage(Handler.java:92)
07-21 23:23:58.039: E/AndroidRuntime(19886):    at android.os.Looper.loop(Looper.java:153)
07-21 23:23:58.039: E/AndroidRuntime(19886):    at android.app.ActivityThread.main(ActivityThread.java:5000)
07-21 23:23:58.039: E/AndroidRuntime(19886):    at java.lang.reflect.Method.invokeNative(Native Method)
07-21 23:23:58.039: E/AndroidRuntime(19886):    at java.lang.reflect.Method.invoke(Method.java:511)
07-21 23:23:58.039: E/AndroidRuntime(19886):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:821)
07-21 23:23:58.039: E/AndroidRuntime(19886):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
07-21 23:23:58.039: E/AndroidRuntime(19886):    at dalvik.system.NativeStart.main(Native Method)
07-21 23:23:58.039: E/AndroidRuntime(19886): Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #2: invalid drawable tag ScrollView
07-21 23:23:58.039: E/AndroidRuntime(19886):    at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:877)
07-21 23:23:58.039: E/AndroidRuntime(19886):    at android.graphics.drawable.Drawable.createFromXml(Drawable.java:818)
07-21 23:23:58.039: E/AndroidRuntime(19886):    at android.content.res.Resources.loadDrawable(Resources.java:1909)
07-21 23:23:58.039: E/AndroidRuntime(19886):    ... 40 more

我想知道是否有更简单的方法来实现这一目标。

1 个答案:

答案 0 :(得分:0)

您不能将布局用作drawable。考虑实施您自己的displayer