나는 TextView
이 레이아웃을 초과 할 때까지 TextView
, 문자열을 넣기를 원했을 때 그 LinearLayout
을 ScrollView
으로 만들었습니다. 문제는 루프가 끝나지 않는 동안 내 코드입니다.증가하는 scrollview의 크기를 관리하는 방법은 무엇입니까?
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();
}
}
});
}
"안드로이드 프레임 워크에서 onMeasure()가 호출되지 않았기 때문에 getMeasuredHeight()가 변경되지 않습니다."답변을 주셔서 감사합니다. "화면을 텍스트로 채우는 것은 좋지 않습니다."그런 식으로 조언 해주십시오. 분리 된 textView에 매우 긴 텍스트를 넣고 각 textView가 전체 화면을 차지하도록하십시오. (각 textView는 pageView에 있으며, 화면에 맞게 텍스트를 구분할 때를 알고 싶습니다.) 고마워요. –
나는 그 문제를 안다는 쉬운 해결책이 없다. 그러나 Frameworks 레이아웃 프로세스를 반복해서 사용하여 적절한 양의 텍스트를 해결해서는 안됩니다. http://stackoverflow.com/questions/14276853/how-to-measure-textview-height-based-on-device-width-and-font-size의 답변에서와 같이 텍스트를 측정하고 올바른 내용을 검색 할 수 있습니다. 텍스트 양. 또는 TextView.getOffsetForPosition()을 사용하여 TextView에서 마지막 문자를 결정하고 다음 페이지에서 다음 문자로 시작하십시오. – thaussma