2011-10-11 3 views
0

Je rencontre un problème étrange lorsque je fais défiler un ScrollView qui contient de longs TextViews. Voici mon code xml:L'affichage de TextView est incorrect quand il est dans ScrollView

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/scroller" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:fillViewport="true" > 
<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 
    <TextView 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:paddingLeft="6dip" 
     android:paddingRight="6dip" 
     android:paddingTop="6dip" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:text="Welcome to My Application" /> 

    <View 
     android:layout_width="fill_parent" 
     android:layout_height="1dip" 
     android:background="#ff106510" 
     android:layout_marginLeft="6dip" 
     android:layout_marginRight="6dip" 
     android:layout_marginTop="6dip" 
     android:layout_marginBottom="12dip" /> 

    <TextView 
     android:id="@+id/longText" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1.0" 

     android:paddingLeft="6dip" 
     android:paddingRight="6dip" 
     android:paddingBottom="6dip" 

     android:text="@string/hello"/> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 

     android:background="@android:drawable/bottom_bar" 
     android:gravity="center_vertical"> 
     <Button 
      android:layout_width="0dip" 
      android:layout_weight="1.0" 
      android:layout_height="wrap_content" 

      android:text="Accept" /> 
     <Button 
      android:layout_width="0dip" 
      android:layout_weight="1.0" 
      android:layout_height="wrap_content" 

      android:text="Refuse" /> 
    </LinearLayout> 
</LinearLayout> 

je suis ce que je veux: The screen shot before scroll

mais quand je défile, le problème se produit: enter image description here

Est-ce que cela arrive jamais à toi? J'ai testé sur un émulateur de SDK2.3.3, un prototype de HTC 2.2, cela arrivera toujours. Quelqu'un peut-il m'aider à me dire pourquoi cela se produit?

Répondre

0

Je viens de trouver la cause racine: Comme je l'ai défini mon activité dans AndroidManifest.xml comme ceci:

<activity 
    android:name=".views.ScrollViewActivity" 
    android:label="@string/scroll_view_sample" 
    android:theme="@style/Theme.NoBackground"> 
    <intent-filter> 
     <action android:name="android.intent.action.MAIN" /> 
     <category android:name="android.intent.category.MY_CUSTOMER_INTENT" /> 
    </intent-filter> 
</activity> 

le thème NoBackground est défini comme ceci:

<resources> 
    <style name="Theme.NoBackground" parent="android:Theme"> 
     <item name="android:windowBackground">@null</item> 
    </style> 
</resources> 

et quand je supprimer la ligne android: theme = "@ style/Theme.NoBackground", ça marche bien.

0

Vous ne manquez pas un </ScrollView> à la fin de votre fichier XML?

EDIT: BTW J'essaye votre XML dans un Archos 70 2.2 ... aucun problème lors du défilement.

Questions connexes