<?xml version="1.0" enCoding="utf-8"?><merge xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" > <com.osmgames.kartuves.linesLayout androID:layout_wIDth="fill_parent" androID:layout_height="fill_parent" androID:ID="@+ID/lines" /></merge>
这是我的linesLayout.java:
public class linesLayout extends FrameLayout { public linesLayout(Context context,AttributeSet attrs) { super(context,attrs); } @OverrIDe protected voID onLayout(boolean changed,int l,int t,int r,int b) { super.onLayout(changed,l,t,r,b); } @OverrIDe public boolean onIntercepttouchEvent(MotionEvent event) { super.onIntercepttouchEvent(event); return false; }}
而我的main.java:
public class main extends Activity { @OverrIDe protected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.main); }}
所以我想将下面的XML扩展到main.xml.我怎样才能做到这一点?
<?xml version="1.0" enCoding="utf-8"?><FrameLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:layout_wIDth="wrap_content" androID:layout_height="fill_parent"> <ImageVIEw androID:layout_wIDth="40dp" androID:layout_height="40dp" androID:layout_gravity="center" androID:layout_margintop="75dp" androID:layout_marginRight="40dp" androID:src="@drawable/line" /> <ImageVIEw androID:layout_wIDth="40dp" androID:layout_height="40dp" androID:layout_gravity="center" androID:layout_margintop="75dp" androID:src="@drawable/line" /> <ImageVIEw androID:layout_wIDth="40dp" androID:layout_height="40dp" androID:layout_gravity="center" androID:layout_margintop="75dp" androID:layout_marginleft="40dp" androID:src="@drawable/line" /></FrameLayout>
这是我得到的日志:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.osmgames.kartuves/com.osmgames.kartuves.InGame}: androID.vIEw.InflateException: <merge /> can be used only with a valID VIEwGroup root and attachToRoot=trueat androID.app.ActivityThread.performlaunchActivity(ActivityThread.java:2663)at androID.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)at androID.app.ActivityThread.access00(ActivityThread.java:125)at androID.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)at androID.os.Handler.dispatchMessage(Handler.java:99)at androID.os.Looper.loop(Looper.java:123)at androID.app.ActivityThread.main(ActivityThread.java:4627)at java.lang.reflect.Method.invokeNative(Native Method)at java.lang.reflect.Method.invoke(Method.java:521)at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:626)at dalvik.system.NativeStart.main(Native Method)Caused by: androID.vIEw.InflateException: <merge /> can be used only with a valID VIEwGroup root and attachToRoot=trueat androID.vIEw.LayoutInflater.inflate(LayoutInflater.java:320)at androID.vIEw.LayoutInflater.inflate(LayoutInflater.java:276)at **com.osmgames.kartuves.InGame.onCreate(InGame.java:59)**at androID.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)at androID.app.ActivityThread.performlaunchActivity(ActivityThread.java:2627)... 11 more
InGame.java:59是:
58 FrameLayout item = (FrameLayout)findVIEwByID(R.ID.lines);59 VIEw child = getLayoutInflater().inflate(R.layout.letters3,null);60 item.addVIEw(child);解决方法 merge标签应该在膨胀的布局中使用,它将自己合并到父VIEwGroup中.
试试这个 :
<?xml version="1.0" enCoding="utf-8"?><FrameLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:layout_wIDth="wrap_content" androID:layout_height="fill_parent"> <com.osmgames.kartuves.linesLayout androID:layout_wIDth="fill_parent" androID:layout_height="fill_parent" androID:ID="@+ID/lines" /></FrameLayout >
还有这个 :
<?xml version="1.0" enCoding="utf-8"?><merge xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" > <ImageVIEw androID:layout_wIDth="40dp" androID:layout_height="40dp" androID:layout_gravity="center" androID:layout_margintop="75dp" androID:layout_marginRight="40dp" androID:src="@drawable/line" /> <ImageVIEw androID:layout_wIDth="40dp" androID:layout_height="40dp" androID:layout_gravity="center" androID:layout_margintop="75dp" androID:src="@drawable/line" /> <ImageVIEw androID:layout_wIDth="40dp" androID:layout_height="40dp" androID:layout_gravity="center" androID:layout_margintop="75dp" androID:layout_marginleft="40dp" androID:src="@drawable/line" /></merge>
希望它会有所帮助
总结以上是内存溢出为你收集整理的android – 在合并中膨胀全部内容,希望文章能够帮你解决android – 在合并中膨胀所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)