2017-06-06 36 views
0

我有一個listView裏面的一個自定義ArrayAdapter呈現的MainActivity的片段。問題是由於某種原因,listview無法滾動。Android ListView在片段不滾動

我的XML MainActivity:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
xmlns:design="http://schemas.android.com/apk/res-auto" 
android:id="@+id/activity_main" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
android:screenOrientation="portrait" 
tools:context=".MainActivity"> 

<FrameLayout 
    android:id="@+id/container" 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:background="#f1f1f1"> 

</FrameLayout> 

<android.support.design.widget.BottomNavigationView 
    android:id="@+id/navigation" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    design:menu="@menu/navigation" /> 
</LinearLayout> 

我的XML片段:

<android.support.constraint.ConstraintLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:screenOrientation="portrait" 
    tools:context=".Friends"> 


<Button 
    android:id="@+id/newfriendbutton" 
    android:layout_width="0dp" 
    android:layout_height="66dp" 
    android:text="@string/new_friend" 
    tools:layout_constraintTop_creator="1" 
    tools:layout_constraintRight_creator="1" 
    android:layout_marginStart="8dp" 
    android:layout_marginEnd="8dp" 
    app:layout_constraintRight_toRightOf="parent" 
    tools:layout_constraintLeft_creator="1" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintTop_toTopOf="parent" /> 

<TextView 
    android:id="@+id/textView6" 
    android:layout_width="395dp" 
    android:layout_height="wrap_content" 
    android:text="@string/instruct" 
    android:textAlignment="center" 
    app:layout_constraintTop_toBottomOf="@+id/newfriendbutton" 
    tools:ignore="MissingConstraints" 
    tools:layout_editor_absoluteX="8dp" /> 

<ListView 
    android:id="@+id/friendListView" 
    android:layout_width="match_parent" 
    android:layout_height="592dp" 
    android:layout_marginEnd="8dp" 
    android:layout_marginStart="8dp" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintRight_toRightOf="parent" 
    app:layout_constraintTop_toBottomOf="@+id/textView6" 
    tools:ignore="MissingConstraints" 
    tools:layout_constraintLeft_creator="1" 
    tools:layout_constraintRight_creator="1" /> 
</android.support.constraint.ConstraintLayout> 
+2

我想你應該嘗試解決您的佈局,'layout_height =「592dp」'不看的權利 –

+0

沒有那不是問題 – Jupiter

+0

你真的應該使用權,沒有固定的尺寸,雖然 –

回答

1

你確定ListView控件是滿了嗎?它只會讓你滾動,如果你在視圖中有更多的選擇,而不是適合給定約束的東西。在這種情況下,最好使用RelativeLayout。

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:screenOrientation="portrait" 
    tools:context=".Friends"> 


    <Button 
     android:id="@+id/newfriendbutton" 
     android:layout_height="66dp" 
     android:text="@string/new_friend" 
     android:layout_width="match_parent" 
     android:layout_marginStart="8dp" 
     android:layout_marginEnd="8dp" 
     android:layout_marginLeft="8dp" 
     android:layout_marginRight="8dp" /> 

    <TextView 
     android:id="@+id/textView6" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/instruct" 
     android:textAlignment="center" 
     android:layout_centerHorizontal="true" 
     android:layout_below="@+id/newfriendbutton"/> 

    <ListView 
     android:id="@+id/friendListView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/textView6" 
     android:layout_marginEnd="8dp" 
     android:layout_marginStart="8dp"/> 
</RelativeLayout> 
+0

的確列表WASN」完整。 – Jupiter