【问题标题】:Unable to render XML无法呈现 XML
【发布时间】:2014-04-24 22:32:43
【问题描述】:

我正在尝试使用SlidingPanel library by Umano。虽然 DemoApp 编译并运行良好。它不呈现 XML。

以下是 XML 在呈现时显示的异常: http://pastebin.com/TZ2iSydg

activity_demo.xml

   <RelativeLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".DemoActivity" >

    <com.sothree.slidinguppanel.demo.SlidingUpPanelLayout
        xmlns:sothree="http://schemas.android.com/apk/res-auto"
        android:id="@+id/sliding_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="bottom"
        sothree:dragView="@+id/name"
        sothree:panelHeight="68dp"
        sothree:paralaxOffset="100dp"
        sothree:shadowHeight="4dp" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:paddingTop="?android:attr/actionBarSize" >

            <TextView
                android:id="@+id/main"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:clickable="true"
                android:focusable="false"
                android:focusableInTouchMode="true"
                android:gravity="center"
                android:text="Main Content"
                android:textSize="16sp" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#eeeeee"
            android:clickable="true"
            android:focusable="false"
            android:orientation="vertical" >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="68dp"
                android:orientation="horizontal" >

                <TextView
                    android:id="@+id/name"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:gravity="center_vertical"
                    android:paddingLeft="10dp"
                    android:textSize="14sp" />

                <Button
                    android:id="@+id/follow"
                    android:layout_width="wrap_content"
                    android:layout_height="match_parent"
                    android:gravity="center_vertical|right"
                    android:paddingLeft="10dp"
                    android:paddingRight="10dp"
                    android:textSize="14sp" />
            </LinearLayout>

            <ImageView
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:scaleType="fitStart"
                android:src="@drawable/graphic" >
            </ImageView>
        </LinearLayout>
    </com.sothree.slidinguppanel.demo.SlidingUpPanelLayout>
</RelativeLayout>

【问题讨论】:

标签: android xml android-layout android-xml


【解决方案1】:

自定义Views 通常不会在 Eclipse 或 IntelliJ 的 UI 编辑器中呈现。这不是悲剧。

但是,如果自定义 View 刚刚显示在 UI 编辑器中,堆栈跟踪建议您应该使用 View.isInEditMode() 跳过呈现。

你可以添加这个:

if(isInEditMode()){
    return;
}

如果您使用的是库的本地副本,请在自定义 View 中的 this 行之后。或者只是向 Github 上的 repo 发送一个拉取请求,这增加了这一点。

【讨论】:

  • 返回错误。 "空白最终字段 mShadowDrawable 可能尚未初始化" mShadowDrawable 是可绘制对象
  • @alexsummers 这不是错误,只是警告。你可以放心地忽略它。
  • 不,仍然没有渲染。
  • @alexsummers 它不会渲染。 Eclipse 和 IntelliJ 中的 UI 编辑器不用于呈现复杂的自定义视图。然而,这两行代码会阻止 UI 编辑器发出无法呈现自定义视图的警告。
  • 哦。应该是某种在线应用程序,您可以在其中粘贴您的 java+xml,它可以让您创建自定义视图并对其进行编辑
猜你喜欢
  • 2016-12-31
  • 2011-12-10
  • 1970-01-01
  • 1970-01-01
  • 2018-10-31
  • 2016-02-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多