English 中文(简体)
膨胀错误 xml 布局文件
原标题:Error inflating xml layout file

我是新来的机器人编程... 所以请耐心...

我试图将自定义视图( ProfessionView) 装入一个活动, 其中我自定义的视图被定义为活动类的子类。 我为包含自定义视图的活动创建了以下 xml 版式文件 :

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/MainLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/ArticleLayout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <aarddict.android.ArticleView // here s the line # 14
            android:id="@+id/ArticleView"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/ButtonLayout"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="5dp"
        android:layout_marginRight="5dp"
        android:gravity="bottom" >

        <Button
            android:id="@+id/NextButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:drawableRight="@drawable/ic_next"
            android:visibility="gone" />
    </LinearLayout>

</RelativeLayout>

接下去,我不停地得到运行时错误(应用程序死亡), 看着LogCat我得到的:

    05-24 23:41:06.685: E/AndroidRuntime(600): java.lang.RuntimeException: Unable to start activity ComponentInfo{aarddict.alidev.android/aarddict.alidev.android.ArticleViewActivity}: android.view.InflateException: Binary XML file line #14: Error inflating class aarddict.android.ArticleView
05-24 23:41:06.685: E/AndroidRuntime(600):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
05-24 23:41:06.685: E/AndroidRuntime(600):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
05-24 23:41:06.685: E/AndroidRuntime(600):  at android.app.ActivityThread.access$600(ActivityThread.java:123)
05-24 23:41:06.685: E/AndroidRuntime(600):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
05-24 23:41:06.685: E/AndroidRuntime(600):  at android.os.Handler.dispatchMessage(Handler.java:99)
05-24 23:41:06.685: E/AndroidRuntime(600):  at android.os.Looper.loop(Looper.java:137)
05-24 23:41:06.685: E/AndroidRuntime(600):  at android.app.ActivityThread.main(ActivityThread.java:4424)
05-24 23:41:06.685: E/AndroidRuntime(600):  at java.lang.reflect.Method.invokeNative(Native Method)

代码 :

interface ScrollListener {
    void onScroll(int l, int t, int oldl, int oldt);
}

private ScrollListener scrollListener;

public ArticleView(Context context) {
    super(context);
}

public ArticleView(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public ArticleView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
}

@Override
protected void onScrollChanged(int l, int t, int oldl, int oldt) {
    super.onScrollChanged(l, t, oldl, oldt);
    if (scrollListener != null) {
        scrollListener.onScroll(l, t, oldl, oldt);          
    }
}

public void setOnScrollListener(ScrollListener l) {
    this.scrollListener = l;
}
}
最佳回答

如果您要创建自定义视图, 您无法将 activity 放在 activity 中, 如果您想要创建一个自定义视图 extend View 或其中的一个子( LinearLayot / / relativeLayoot /code>/ / / /retalLayout )

http://developmenter.android.com/guide/topics/ui/custic-partics.html

问题回答

Correct Answer is wrong. You can define different activities on project. Error is simple
aarddict.android.ArticleView must be yourpackagename.ArticleView





相关问题
Very basic WPF layout question

How do I get this listbox to be maxiumum size, i.e. fill the group box its in. I ve tried width="auto" Height="auto", width="stretch" Height="stretch" annoyingly at the moment, it dynamicly sizes to ...

How to align the text to top of TextView?

How to align the text to top of a TextView? Equivalent Android API for Swings setInsets()? that is top of text should start be in (0,0) of TextView <?xml version="1.0" encoding="utf-8"?> <...

Centring a flow in Shoes

Can I center the contents of a flow in Shoes? I know that a paragraph can be centred like: para Centred paragrpah , :align=> center However, this does not work with flows: flow(:align=> ...

Overlaying with CSS

I want to load a website in an iframe, and overlay the website with some hints about the website that is shown. However, i got stuck at the point that the website has a variable passive white space at ...

How do you normally make a program look beautiful? [closed]

How can I make an Application look nice and not like an amateur pulled it together? I mean graphic-wise. Is there some sort of book you can read regarding beautiful program layouts, etc? I put this ...