在布局xml使用自定义ViewGroup,使用setContentView(R.layout.activity_main)就出错

craboy1 2014-11-12 10:18:54

<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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<com.example.viewgroup2.TestViewGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/myTestVG"
>

</com.example.viewgroup2.TestViewGroup>

</RelativeLayout>





package com.example.viewgroup2;

import android.content.Context;
import android.view.ViewGroup;

public class TestViewGroup extends ViewGroup {

public TestViewGroup(Context context) {
super(context);
// TODO Auto-generated constructor stub
}

@Override
protected void onLayout(boolean arg0, int arg1, int arg2, int arg3, int arg4) {
// TODO Auto-generated method stub

}

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

}

}


package com.example.viewgroup2;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity {

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

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

}


...全文
164 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
哎,真难 2014-11-13
  • 打赏
  • 举报
回复
报什么错误,,,
craboy1 2014-11-12
  • 打赏
  • 举报
回复
编译能通过,但运行不了。

80,362

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧