2012-06-06 1 views
2

Android에서 새로운 기능이며 스크롤 가능한 텍스트가 포함 된 페이지를 만들려고합니다. 선형 레이아웃과 스크롤을 사용하여 상대 레이아웃을 사용하고 있습니다. 그러나 어쨌든 텍스트는 시작부터 페인트가 아닙니다.Android 레이아웃에서 다른 버튼이있는 페이지의 스크롤 가능한 텍스트보기

처음 세 줄은 스크롤 영역 외부에 있으므로 (Title1, Title2, Title3) 그려지지 않습니다. 하지만 왜? 스크롤은 다음과 같은 두 개의 버튼에서 지정된 영역의 잘 작동합니다 : 여기에 설정했습니다. android : layout_below = "@ id/button_s" android : layout_above = "@ id/button_c"스크롤의 여백이지만 여전히 텍스트입니다. 여백 밖에있는 디스플레이입니다. 내가 뭘 잘못 했니? 왜 선형 레이아웃 lin2는 텍스트를 그리는가 화면 상단에서 시작하는 이유는 무엇입니까? 나는 그것을 android : layout_below로 설정했다.

이 main.xml에 :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/relative_layout" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 


<TextView 
    android:id="@+id/tv" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:text="@string/my_app" /> 

<Button 
    android:id="@+id/button_s" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:layout_below="@id/tv" 
    android:text="@string/search" /> 

<Button 
    android:id="@+id/button_c" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentBottom="true" 
    android:text="@string/config" /> 

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:scrollbars="vertical" 
    android:layout_below="@id/button_s" 
    android:layout_above="@id/button_c" android:id="@+id/ScrollView"> 

    <LinearLayout 
     android:layout_width="fill_parent"      
     android:orientation="vertical" 
     android:id="@+id/lin2" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/button_s" 
     android:layout_above="@id/button_c" 
     android:layout_gravity="center_vertical|center_horizontal"> 

    </LinearLayout> 
</ScrollView> 


</RelativeLayout> 

내 자바 파일 :

String[] strTitles ={"Title 1: test test test test test test test test", 
         "Title 2: test test test test test", 
         "Title 3: test test test test test", 
         "Title 4: test test test test", 
         "Title 5: test test test", 
         "Title 6: test test test test", 
         "Title 7: test test test test", 
         "Title 8: test test test test test", 
         "Title 9: test test test test test", 
         "Title 9: test test test test test", 
         "Title 10: test test test test", 
         "Title 11: test test test test test", 
         "Title 12: test test test test test", 
         "Title 13: test test test test test", 
         "Title 14: test test "}; 
/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    LinearLayout ll = (LinearLayout)findViewById(R.id.lin2); 

    for (int i = 0 ; i < strTitles.length * 2 ; i++) 
    { 
     String strToDisplay = " "; 
     if(i%2 == 1) 
      strToDisplay = " "; 
     else 
     { 
      strToDisplay = strTitles[i/2]; 
     } 

     TextView tv = new TextView(this); 
     tv.setText(strToDisplay); 
     ll.addView(tv); 
     tv.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL); 

    } 

} 

감사

답변

1

layout_gravity만을위한 center_horizontal로 변경 여기

내 코드입니다 LinearLayout lin2 : 부모 ScrollView 높이 wrap_content로 설정되어있을 때 당신은 또한 center_vertical을 넣어 왜 이해가 안

android:layout_gravity="center_horizontal" 

.

+0

@ 도리안 루프에서 "\ n"을 사용할 수도 있습니다. for (int i = 0; i jayellos

+0

감사합니다. Luksprog. 이제 작동합니다. – Dorian

+0

감사합니다. marvz - 네가 맞아. – Dorian

관련 문제