【发布时间】:2011-02-20 18:53:41
【问题描述】:
我已经坐了至少 4 个小时试图解决这个问题。
要理解这一点,您需要了解 3 个文件:
eggCatcher.java 扩展了Activity,这个类用的不多 保存游戏状态并显示选项菜单。
eggCatcherView.java 扩展了 SurfaceView 并包含“游戏”。
eggCatcher_layout.xml 如下所示:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/layouten">
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<easter.fun.EggCatcherView
android:id="@+id/eggcatcher"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<RelativeLayout android:id="@+id/relativeLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true">
<TextView android:text="Score: "
android:id="@+id/totalscore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true">
</TextView>
<TextView android:text="Bonus: "
android:id="@+id/bonus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true">
</TextView>
</RelativeLayout>
</FrameLayout>
</LinearLayout>
如xml文件所示,将EggCatcherView放在xml文件中。 当我启动 onCreate 的应用程序调用 setContentView(layout.eggcatcher_layout);
我现在的问题是: 我如何从 EggCatcherView.java 访问和编辑 xmlfile 中定义的 TextViews?
如果它在 EggCatcher.java 中会很容易,只需使用 findViewById(id.bonus),但从 在surfaceView里面似乎有点困难。
我希望我已经把一切都说清楚了,如果你不明白,请问!
//米克
【问题讨论】:
标签: java android xml android-layout