所以,我已经找到了答案。大多数结果显示如何从布局外部更新。这是我的简化代码。
MainActivity:
public class MainActivity extends Activity{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{ this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LinearLayout surface = (LinearLayout)findViewById(R.id.surface);
surface.addView(new UnitActivity(this));}}
UnitActivity:
public class UnitActivity extends SurfaceView
{
private MainThread thread;
private SurfaceHolder holder;
public UnitActivity(Context context){
super(context);touch = new MyTouchListener();
this.setOnTouchListener(touch);
thread = new MainThread(this);
holder=getHolder();
holder.addCallback(new SurfaceHolder.Callback(){
@Override
public void surfaceCreated(SurfaceHolder p1)
{
thread.setRunning(true);
thread.start();
}
@Override
public void surfaceChanged(SurfaceHolder p1, int p2, int p3, int p4)
{
// TODO: Implement this method
}
@Override
public void surfaceDestroyed(SurfaceHolder p1)
{
boolean retry = true;
while (retry)
{
try
{
thread.join();
retry = false;
}
catch(Exception e){
}
}
}
});
setFocusable(true)
}
@Override
public void onDraw(Canvas c) {
//draw to canvas here
*******Here is where I want to, in some way
make a call to add a ScrollView or
TextView to the original Layout******
}
}
基本上,我的SurfaceView
正在更新运行Thread
。我希望某个条件触发TextView
或ScrollView
在屏幕上显示。我想也许我可以让布局运行一个线程并更新自己,但杀了我的应用程序这样做...我感谢任何帮助或评论。