使用ListView滚动LinearLayout可滚动

时间:2018-05-25 08:02:45

标签: java android listview scrollview android-linearlayout

我的线性布局看起来像这样:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linear_layout"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:orientation="vertical"
    tools:context=".activities.EnrolStudentFormActivity">

    <include
        layout="@layout/app_bar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:fitsSystemWindows="true" />

    <ListView
        android:id="@+id/list_view
        android:layout_width="match_pare
        android:layout_height="wrap_cont
        android:divider="@null"
        android:dividerHeight="0dp" />

</LinearLayout>

中间有少量ImageViewTextInputLayoutTextInputEditText。我想让这个布局可滚动。我尝试使用ScrollViewNestedScrollView滚动它,但它们都混淆了ListView

我也在动态更改ListView内容,TextInputEditText内的TextInputLayout内有ListViewListView。调整TextInputEditText的大小无济于事,我无法点击ListView内的ScrollView。似乎ListView捕获了触摸输入。

是否有任何变通方法可以让我在ScrollView内设置TextInputEditText或者使ListView内的class DomainMeta(type): ENTITIES = {} def __new__(cls, name, bases, attrs): cls = type.__new__(cls, name, bases, attrs) try: entity = attrs['domain'] cls.ENTITIES[entity] = cls except KeyError: pass return cls class Domain(metaclass=DomainMeta): @classmethod def factory(cls, domain): return DomainMeta.ENTITIES[domain]() class RegistrarA(Domain): domain = 'test.com' def lookup(self): return 'Custom command for .com TLD' class RegistrarB(Domain): domain = 'test.biz' def lookup(self): return 'Custom command for .biz TLD' com = Domain.factory('test.com') type(com) # <class '__main__.RegistrarA'> com.lookup() # 'Custom command for .com TLD' com = Domain.factory('test.biz') type(com) # <class '__main__.RegistrarB'> com.lookup() # 'Custom command for .biz TLD' 可用时线性布局可滚动?

1 个答案:

答案 0 :(得分:0)

使用RecyclerView代替ListView并在上方添加NestedScrollView

<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:android="
http://schemas.android.com/apk/res/android"
xmlns:http="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/linear_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:orientation="vertical"
    tools:context=".activities.EnrolStudentFormActivity">

    <include
        layout="@layout/app_bar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:fitsSystemWindows="true" />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/list_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:divider="@null"
        android:dividerHeight="0dp" />>

</LinearLayout>

最后在你的代码中添加:

RecyclerView.setNestedScrollingEnabled(false);