2014-06-28 125 views
0

我有一個ListView不滾動完成。我插入了20個項目,但列表視圖正在滾動,直到項目15º。列表視圖不滾動完全android

我的佈局XML代碼在這裏:

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

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="0.6" 
     android:background="@color/sky" > 

     <TextView 
      android:id="@+id/tvQuote" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_centerInParent="true" 
      android:layout_marginLeft="6dp" 
      android:layout_marginRight="6dp" 
      android:gravity="center_vertical|center_horizontal" 
      android:scrollbars="none" 
      android:text="@string/QuoteTeste" 
      android:textAlignment="center" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:textColor="@color/white" 
      android:textSize="14pt" /> 

     <Space 
      android:id="@+id/espaco" 
      android:layout_width="wrap_content" 
      android:layout_height="30dp" > 
     </Space> 

     <TextView 
      android:id="@+id/tvAutor" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignRight="@+id/tvQuote" 
      android:layout_below="@+id/tvQuote" 
      android:layout_marginTop="22dp" 
      android:text="(Carlos Drummond)" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:textColor="@color/white" /> 
    </RelativeLayout> 

    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" > 

     <ListView 
      android:id="@+id/checklistview" 
      android:layout_width="fill_parent" 
      android:layout_height="match_parent" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentTop="true" > 
     </ListView> 

    </RelativeLayout> 

</LinearLayout> 

下面的截圖: My view

爲什麼發生這種情況,我不明白。例如,如果我放6個項目,6º項目不顯示,我不能滾動列表視圖。遺漏了什麼?

回答

1

的問題是在你的佈局XML

這一個變化是:

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

    <RelativeLayout 
     android:id="@+id/topPart" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@color/sky" > 

     <TextView 
      android:id="@+id/tvQuote" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_centerInParent="true" 
      android:layout_marginLeft="6dp" 
      android:layout_marginRight="6dp" 
      android:gravity="center_vertical|center_horizontal" 
      android:scrollbars="none" 
      android:text="@string/QuoteTeste" 
      android:textAlignment="center" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:textColor="@color/white" 
      android:textSize="14pt" /> 

     <Space 
      android:id="@+id/espaco" 
      android:layout_width="wrap_content" 
      android:layout_height="30dp" > 
     </Space> 

     <TextView 
      android:id="@+id/tvAutor" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignRight="@+id/tvQuote" 
      android:layout_below="@+id/tvQuote" 
      android:layout_marginTop="22dp" 
      android:text="(Carlos Drummond)" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:textColor="@color/white" /> 
    </RelativeLayout> 

    <ListView 
     android:id="@+id/checklistview" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@+id/topPart" > 
    </ListView> 


</RelativeLayout> 
+0

我試過,但我的ListView消失,第一RelativeLayout的(藍色用的TextView)填滿所有的屏幕。這裏截圖[鏈接](http://hhide.me/KxB) – rochasdv

+1

我改變了第二個相關佈局高度。你可能還想補充一些利潤 – Benoit

+0

那麼你有沒有嘗試過這麼小的改變? – Benoit

0

你不應該使用的Android低於對方添加多個enties:layout_height = 「FILL_PARENT」 或 「match_parent」(這與您在LinearLayout中的佈局相同)。

使用layout_below,layout_parentOnBottom和其他選項使其成爲另一個RelativeLayout,或將所有內容放入一個巨大的相對佈局中。

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

<RelativeLayout 
    android:id="@+id/toppart" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentTop="true" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@color/sky" > 

    <TextView 
     android:id="@+id/tvQuote" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:layout_marginLeft="6dp" 
     android:layout_marginRight="6dp" 
     android:gravity="center_vertical|center_horizontal" 
     android:scrollbars="none" 
     android:text="@string/QuoteTeste" 
     android:textAlignment="center" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:textColor="@color/white" 
     android:textSize="14pt" /> 

    <Space 
     android:id="@+id/espaco" 
     android:layout_width="wrap_content" 
     android:layout_height="30dp" > 
    </Space> 

    <TextView 
     android:id="@+id/tvAutor" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignRight="@+id/tvQuote" 
     android:layout_below="@+id/tvQuote" 
     android:layout_marginTop="22dp" 
     android:text="(Carlos Drummond)" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:textColor="@color/white" /> 
</RelativeLayout> 

<RelativeLayout 
    android:id="@+id/bottompart" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentRight="true" 
    android:layout_alignParentBottom="true" 
    android:layout_below="@+id/toppart" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" > 

    <ListView 
     android:id="@+id/checklistview" 
     android:layout_width="fill_parent" 
     android:layout_height="match_parent" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" > 
    </ListView> 

</RelativeLayout> 

+0

是的,你可以但是然後你得到他的結果;) – Benoit

+1

替換「可以」,「應」;-) – brummfondel

+0

對不起,你能爲你在說什麼發表一些代碼嗎? – rochasdv