Android以编程方式使用形状
我想运行MainActivity,它扩展了View但它没有运行。我是否必须使用MainActivity extends Activity来运行应用程序,因为我想在MainActivity类中使用draw()方法。我可以直接使用它,或者我必须使用View而不是Activity ?. 这里是我的代码Android以编程方式使用形状
public class MainActivity extends View {
public MainActivity(Context context) {
super(context);
}
的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:background="#000000"
android:gravity="center"
android:orientation="vertical" >
</LinearLayout>
是的,您的主要活动(以及任何其他)必须扩展活动。 如果您想制作自己的自定义控件,只需将其写入(扩展视图或其某些下降图),并将其与其他任何控件一起放入主布局。 在您的自定义控件中,如果需要,可以重写onDraw()方法。 看看文档: Custom controls
在你的教程中他们是没有布局文件 – OmD 2013-03-23 10:54:11
它是完整的教程的朋友。尝试一下。那么你会意识到 – Gunaseelan 2013-03-24 13:43:31
尝试类似:
class MyActivity extends Activity {
...
@Override
protected void onCreate {
...
setContentView(R.layout.main);
....
}
}
你setContentView
后,您可以通过调用findViewById(<LinearLayout's id>)
引用它。在您的布局中,您可以放置您想要执行绘图的视图
@部门谢谢你的信息 – OmD 2013-03-23 10:53:26
谢谢你的答案 – OmD 2013-03-23 10:53:08