【发布时间】:2013-05-22 17:20:49
【问题描述】:
我创建了ScrollView,并在其LinearLayout 中添加了TextView,
我只想将字符串放入其中,直到 TextView 超出布局。
我的代码的问题是 while 循环永远不会结束。
public class MainActivity extends Activity {
public static int screenWidth,screenHeight;
public boolean overlap;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main) ;
ScrollView scroll=(ScrollView) findViewById(R.id.scrollView1);
TextView mytextview=(TextView) findViewById(R.id.textview1);
TextView textshow=(TextView) findViewById(R.id.textView2);
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.linearlayout);
mytextview.setText("");
ViewTreeObserver vto=scroll.getViewTreeObserver();
getmeasure(vto,mytextview,scroll,linearLayout);
}
public void getmeasure(ViewTreeObserver vto, final TextView mytextview2, final ScrollView scroll2, final LinearLayout linearLayout2) {
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
int a=linearLayout2.getMeasuredHeight();
int b=scroll2.getHeight();
while (a<b) {
mytextview2.append("full full full");
a=linearLayout2.getMeasuredHeight();
b=scroll2.getHeight();
}
}
});
}
【问题讨论】:
标签: android android-scrollview