请帮我我自定义布局在android系统 [英] Please help me me in custom layout in android

查看:112
本文介绍了请帮我我自定义布局在android系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 了java.lang.RuntimeException:无法启动的活动`ComponentInfo {com.example.demo / com.example.demo.Demo}:android.view.InflateException:二进制XML文件中的行#7:错误充气类com.example.component.MainActivity`


 公共类MainActivity扩展的FrameLayout {
    公共MainActivity(上下文的背景下){
        超级(上下文);
        // TODO自动生成构造函数存根
    }
}


activity_main.xml中

 <的RelativeLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    的xmlns:工具=htt​​p://schemas.android.com/tool​​s
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    工具:上下文=MainActivity。>    <的TextView
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_centerHorizo​​ntal =真
        机器人:layout_centerVertical =真
        机器人:文字=@字符串/参考hello world/>< / RelativeLayout的>

Demo.java

 公共类演示扩展活动{    @覆盖
    保护无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_demo);
    }
}

activity_demo.xml

 <的FrameLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    的xmlns:工具=htt​​p://schemas.android.com/tool​​s
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
 >  < com.example.component.MainActivity
    机器人:ID =@ + ID /补偿
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
      />
< /&的FrameLayout GT;


解决方案

由于演示是你的活动,通过包名的Andr​​oid manifest.xml文件定义它:
com.example.demo.Demo。
而你为什么里面的FrameLayout添加的FrameLayout只使用一个,你自定义的FrameLayout。
和定义XML为:

 < com.example.component.MainActivity
    的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    的xmlns:工具=htt​​p://schemas.android.com/tool​​s
    机器人:ID =@ + ID /补偿
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
 />

//希望工程

java.lang.RuntimeException: Unable to start activity `ComponentInfo{com.example.demo/com.example.demo.Demo}: android.view.InflateException: Binary XML file line #7: Error inflating class com.example.component.MainActivity`

public class MainActivity extends FrameLayout {    
    public MainActivity(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
    }
}

activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/hello_world" />

</RelativeLayout>

Demo.java

public class Demo extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_demo);
    }


}

activity_demo.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
 >

  <com.example.component.MainActivity
    android:id="@+id/comp"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
      />
</FrameLayout>

解决方案

Since Demo is your Activity, define it in Android manifest.xml file using the package name: com.example.demo.Demo. And why are you adding framelayout inside frameLayout use only one , your custom framelayout. and define the xml as:

<com.example.component.MainActivity
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/comp"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
 />

//hope it works

这篇关于请帮我我自定义布局在android系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆