ListView 不与父 LinearLayout 一起滚动?
ListView not Scrolling with parent LinearLayout?
我有一个主 ScrollView,然后我有一个子 LinearLayout,其中有 ListView。我不确定为什么它不滚动。我读到 listview 不应该在滚动视图内,但我需要我的布局滚动然后查看 listview。我不确定这是否是正确的方法。请指点。
这适用于我的大屏幕平板电脑,但不适用于我的 phone 屏幕较小的平板电脑,您需要滚动才能完整查看列表视图。如果我使用线性布局,列表视图可以工作,但是我看不到列表视图,因为它位于布局的底部。
<?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>
我遇到了同样的问题。这是我的代码。看看吧。
<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。
尝试用 LinearLayout 替换您的 ListView 并在其中添加您要添加到列表视图中的相同项目(视图)
我有一个主 ScrollView,然后我有一个子 LinearLayout,其中有 ListView。我不确定为什么它不滚动。我读到 listview 不应该在滚动视图内,但我需要我的布局滚动然后查看 listview。我不确定这是否是正确的方法。请指点。
这适用于我的大屏幕平板电脑,但不适用于我的 phone 屏幕较小的平板电脑,您需要滚动才能完整查看列表视图。如果我使用线性布局,列表视图可以工作,但是我看不到列表视图,因为它位于布局的底部。
<?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>
我遇到了同样的问题。这是我的代码。看看吧。
<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。
尝试用 LinearLayout 替换您的 ListView 并在其中添加您要添加到列表视图中的相同项目(视图)