我定义的扩展了的LinearLayout的功能的自定义的ViewGroup:
I've defined a custom ViewGroup that extends the functionality of a LinearLayout:
public class TestLayout extends LinearLayout {
public TestLayout(Context context, AttributeSet attrs) {
super(context, attrs);
LayoutInflater inflater = (LayoutInflater)context.getSystemService
(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.testlayout, this, true);
}
}
布局它膨胀( testlayout.xml )看起来是这样的:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" android:gravity="center">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"/>
</LinearLayout>
终于我现在在用这个自定义组件我的 main.xml中
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<my.test.namespace.TestLayout
android:id="@+id/testLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</my.test.namespace.TestLayout>
</LinearLayout>
在看我在布局编辑器main.xml中,日食引发错误:的 my.test.namespace.TestLayout失败的实例。的
When viewing my main.xml in the layout editor, eclipse throws an error: my.test.namespace.TestLayout failed to instantiate.
和堆栈跟踪:
android.content.res.Resources$NotFoundException: Could not resolve resource value: 0x7F030001.
at com.android.layoutlib.bridge.android.BridgeResources.throwException(BridgeResources.java:648)
at com.android.layoutlib.bridge.android.BridgeResources.getLayout(BridgeResources.java:270)
at android.view.LayoutInflater.inflate(LayoutInflater.java:318)
at my.test.namespace.TestLayout.<init>(TestLayout.java:18)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.instantiateClass(ProjectCallback.java:397)
at com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.loadView(ProjectCallback.java:165)
at com.android.layoutlib.bridge.android.BridgeInflater.loadCustomView(BridgeInflater.java:205)
at com.android.layoutlib.bridge.android.BridgeInflater.createViewFromTag(BridgeInflater.java:133)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
0x7F030001 指向R.java布局xml文件。我试图清理我的项目,但什么也没做。我使用的LayoutInflater错了,或者是怎么回事呢?
0x7F030001 points to the layout xml file in R.java. I tried cleaning my project, but that did nothing. Am I using the LayoutInflater wrong, or what is going on here?
下面通常帮助:
清理项目(同样,以防万一)。重新启动Eclipse。刷新您的文件夹在Eclipse(右键 - >刷新,或选择你的顶层文件夹和preSS F5)。