【发布时间】:2015-12-14 10:09:34
【问题描述】:
我已经花了几个小时搜索和尝试,但我无法走上正确的道路。
首先是我的代码:
public class MyThreadLoc extends Thread{
Context context;
final ViewGroup view;
MyThreadLoc(Context context){
super();
this.context = context;
view = (ViewGroup) findViewById(R.id.mLayout);
}
int height;
@Override public void run() {
Looper.prepare();
int i = 0;
int y = 10;
while(running && i < 20){
i++;
if(y >= 200){
runOnUiThread(new Runnable() {
public void run() {
view.removeAllViews();
view.setBackgroundColor(Color.BLACK);
}
});
y=10;
}
try {
Thread.sleep( 500 );
Log.d("mystuff", "Sleep");
} catch ( InterruptedException e ) { e.printStackTrace(); }
final ViewGroup.LayoutParams lParam = new ViewGroup.LayoutParams(500,30); //MATCH_PARENT, 30);
while(y < 200 && running){
final float yb = y;
runOnUiThread(new Runnable() {
TextView tview;
public void run() {
Log.d("mystuff", "innerrun");
synchronized (view){
tview = new TextView(context);
tview.setText("Test");
tview.setY(yb);
view.addView(tview, lParam);
height = tview.getHeight();
view.updateViewLayout(tview, new RelativeLayout.LayoutParams(500,30));
Log.d("mystuff", Integer.toString(view.getChildCount()));
try {
Thread.sleep( 50 );
Log.d("mystuff", "Sleep");
} catch ( InterruptedException e ) { e.printStackTrace(); }
}
}
});
y = y + 100; //height +5;
}
视图不会首先出现,但最后会出现 2 个带有“测试”的文本视图。 我怎样才能更新它,以便我看到出现的每一个文本视图?
【问题讨论】:
-
你想做什么?