2010-12-03 9 views
1

je le code XML suivant et ne fais rien de fantaisie avec dépassement des comportements de défilement:ScrollView ne répond pas

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 
    <ScrollView 
     android:id="@+id/myscrollview" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:fillViewport="true" 
     android:layout_weight="1"> 
      <ListView 
       android:id="@+id/mylistview" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" /> 
    </ScrollView> 
    <TextView 
     android:id="@+id/my_empty" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:text="@string/my_foo" 
     android:gravity="center" 
     android:visibility="gone" 
    /> 
</LinearLayout> 

Cependant, alors que le listview embarqué ne répond aux presses et presses longues, il ne défile pas. Qu'est-ce que je fais mal?

Le TextView final est la vue vide de la listview.

+1

Vous êtes tous gagnants à mes yeux. – SapphireSun

Répondre

4

ScrollView ne joue pas bien avec tout autre point de vue qui défile en mode natif, à savoir WebView, ListView, etc.

Essayez une disposition relative et voir si cela fait ce dont vous avez besoin.

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" > 

<ListView 
    android:id="@+id/mylistview" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_alingParentTop="true" 
/> 
<TextView 
    android:id="@+id/my_empty" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/my_foo" 
    android:gravity="center" 
    android:visibility="gone" 
    android:layout_alignParentBottom="true" 
/> 
</RelativeLayout> 
2

Dans Android, il ne doit pas mettre ListView dans un ScrollView. Ça ne marchera pas.

2

Sortez le ListView du ScrollView. Il provoque des problèmes, et il est inutile (ListView gère le défilement lui-même.)