我的问题很简单。我有扩展 GLSurfaceView 的类 TouchSurfaceView。我想创建活动,底部有三个 TextView 和 Button,顶部有 TouchSurfaceView,但我不知道如何在 XML 布局中读取它。
1 回答
0
您只需使用全名(包括包)引用它,就像它是任何其他 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
}
于 2011-06-05T04:38:44.587 回答