2014-03-24 3 views
1

도서 리더 어플리케이션을 개발 중입니다. LinearLayout 있습니다.Textview를 식별하는 방법은 화면 하단에 도달 했습니까?

<LinearLayout 
    android:id="@+id/llReader" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_marginLeft="20dp" 
    android:layout_marginRight="20dp" 
    android:orientation="vertical" > 
</LinearLayout> 

줄 단위로 내부 저장소에서 html 파일을 가져오고 있습니다. 한 줄에 하나의 텍스트보기를 할당하고이를 LinearLayout에 넣고 있습니다.

private void readFile(LinearLayout ll) throws IOException { 

     fileName = myDatabase.getBookById(book_id) + ".html"; 

     FileInputStream fis = openFileInput(fileName); 
     BufferedReader br = new BufferedReader(new InputStreamReader(fis)); 

     String line = ""; 

     while (null != (line = br.readLine())) { 

      TextView tv = new TextView(this); 
      tv.setTextSize(24); 
      tv.setText(Html.fromHtml(line)); 
      ll.addView(tv); 
     } 
     br.close(); 
    } 

어떻게 TextViews가 화면 하단에 도달했는지 식별하는 방법은 무엇입니까?

답변

1

할 수 있습니다 픽셀 조작을 통해 : 답변

private void readFile(LinearLayout ll) throws IOException { 

    fileName = myDatabase.getBookById(book_id) + ".html"; 

    FileInputStream fis = openFileInput(fileName); 
    BufferedReader br = new BufferedReader(new InputStreamReader(fis)); 

    String line = ""; 

    int parentHeight = ll.getHeight(); // in pixels 
    int sumHeigth = 0; 

    while (null != (line = br.readLine())) { 

     TextView tv = new TextView(this); 
     tv.setTextSize(24); 
     tv.setText(Html.fromHtml(line)); 
     ll.addView(tv); 
     sumHeigth += tv.getHeight(); 
     if(sumHeigth>parentHeight) { 
      // if can't fit in LinearLayout 
      ll.removeView(tv); 
      // break; // or what you want in this situation 
     } 
    } 
    br.close(); 
} 
+0

들으하지만 내부에 넣을 때 잠시 'Log.d ("AkitaLog", "sumHeight :"+ sumHeigth + "; parentHeight :"+ parentHeight);' ** 03-25 20 : 51 : 29.800 : D/AkitaLog (2825) : sumHeight : 0; parentHeight : 0 ** – user3388473

관련 문제