【发布时间】:2011-06-04 16:57:09
【问题描述】:
我的问题很简单。我有扩展 GLSurfaceView 的类 TouchSurfaceView。我想在底部创建三个 TextView 和 Button 以及顶部的 TouchSurfaceView 的活动,但我不知道如何在 XML 布局中读取它。
【问题讨论】:
标签: android xml android-linearlayout glsurfaceview
我的问题很简单。我有扩展 GLSurfaceView 的类 TouchSurfaceView。我想在底部创建三个 TextView 和 Button 以及顶部的 TouchSurfaceView 的活动,但我不知道如何在 XML 布局中读取它。
【问题讨论】:
标签: android xml android-linearlayout glsurfaceview
您只需使用全名(包括包)引用它,就好像它是任何其他 Vew:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<your.package.TouchSurfaceView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="text"
/>
<!-- etcetera -->
</LinearLayout>
您需要一个以 AttributeSet 作为参数的构造函数(在膨胀 xml 时使用):
public TouchSurfaceView(Context context, AttributeSet attr) {
super(context, attr);
// the rest of your code
}
【讨论】:
<cz.audiorecenze.TouchSurfaceView android:layout_width=.... 但 logcat 写道:06-05 08:50:52.025: ERROR/AndroidRuntime(543): java.lang.RuntimeException: Unable to start activity ComponentInfo{cz.audiorecenze/cz.audiorecenze.MainActivity}: android.view.InflateException: Binary XML file line #15: Error inflating class cz.audiorecenze.TouchSurfaceView