2016-03-03 98 views
0

我有一個主滾動視圖,然後我有一個孩子LinearLayout,並有ListView中。我不確定它爲什麼不滾動。我讀過有關如何不應該在滾動視圖內的ListView,但我需要我的佈局滾動,然後查看列表視圖。我不確定這是否合適。請指導。ListView不滾動與父LinearLayout?

這適用於我的平板電腦與大屏幕,但不是我的手機有一個較小的屏幕,你需要滾動查看完整的列表視圖。如果我使用線性佈局但是我沒有看到完整的列表視圖,因爲它在佈局的底部。

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

<LinearLayout 
    android:id="@+id/user_info" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:focusable="true" 
    android:focusableInTouchMode="true" 
    android:paddingTop="46dp" 
    android:paddingLeft="24dp" 
    android:paddingRight="24dp" > 

    <Spinner 
     android:id="@+id/userTypeSpinner" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="8dp" /> 

    <android.support.design.widget.TextInputLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="8dp"> 
     <EditText android:id="@+id/fname" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:inputType="text" 
      android:hint="First Name"/> 
    </android.support.design.widget.TextInputLayout> 

    <android.support.design.widget.TextInputLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="8dp" > 
     <EditText android:id="@+id/lname" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:inputType="text" 
      android:hint="Last Name"/> 
    </android.support.design.widget.TextInputLayout> 

    <LinearLayout 
     android:id="@+id/staff_username" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:visibility="gone" > 

     <android.support.design.widget.TextInputLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="8dp" > 
      <EditText android:id="@+id/uname" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:inputType="text" 
       android:hint="Username"/> 
     </android.support.design.widget.TextInputLayout> 

    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/staff_password" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:visibility="gone" > 

     <android.support.design.widget.TextInputLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="8dp" > 
      <EditText android:id="@+id/upassword" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:inputType="textPassword" 
       android:hint="Password"/> 
     </android.support.design.widget.TextInputLayout> 

    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/staff_email" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:visibility="gone" > 

     <android.support.design.widget.TextInputLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="8dp" > 
      <EditText android:id="@+id/uemail" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:inputType="text" 
       android:hint="Email"/> 
     </android.support.design.widget.TextInputLayout> 

    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/staff_permissions" 
     android:layout_marginTop="8dp" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:visibility="gone" 
     > 

     <ListView 
      android:id="@+id/permission_list" 
      android:layout_width="fill_parent" 
      android:layout_height="200dp" 
      android:fadeScrollbars="false" 
      /> 

    </LinearLayout> 

    <android.support.v7.widget.AppCompatButton 
     android:id="@+id/addUserBtn" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="24dp" 
     android:layout_marginBottom="24dp" 
     android:padding="12dp" 
     android:text="@string/add_new_user"/> 

</LinearLayout> 

+4

[滾動視圖內的Android列表視圖(HTTP的可能重複在這同一項目(視圖)://計算器。 com/questions/18367522/android-list-view-inside-a-scroll-view) –

+0

你不應該使用ScrollView。沒有ScrollView它會工作。 –

+0

它沒有它的工作,但你看不到它,因爲屏幕很小,這就是爲什麼我使用scrollview向下滾動佈局 –

回答

0

同樣的問題,我有。這是我的代碼。一探究竟。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/login_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/login" 
    android:gravity="center" 
    android:orientation="vertical" > 

    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 

     <LinearLayout 
      android:layout_width="250dp" 
      android:layout_height="270dp" 
      android:layout_marginTop="40dp" 
      android:gravity="center" 
      android:orientation="vertical" > 

      <LinearLayout 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="30dp" 
       android:orientation="vertical" > 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="@string/username_login" /> 

       <EditText 
        android:id="@+id/username_login" 
        android:layout_width="200dp" 
        android:layout_height="30dp" 
        android:background="@drawable/edit_text" 
        android:inputType="text" 
        android:paddingLeft="5dp" 
        android:paddingTop="2dp" /> 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="@string/password_login" /> 
      </LinearLayout> 
     </LinearLayout> 
    </ScrollView> 

</LinearLayout> 

不要使用scrollview作爲父項。只需在父佈局中使用滾動視圖即LinearLayout或RelativeLayout。

+0

哪裏是listview? –

+0

我在這段代碼中沒有使用過listview。但我給你瞭解scrollview是如何工作的。滾動查看可能是你的列表視圖不滾動的原因。只需嘗試一次。希望它可以幫助你。 –

0

嘗試用LinearLayout中更換你的ListView,並添加要在您的列表視圖中添加