【问题标题】:how do I make my whole display to be scrollable如何使我的整个显示可滚动
【发布时间】:2020-08-27 12:35:12
【问题描述】:

我正在为我的餐厅制作一个应用程序,当用户进入餐厅页面时,他或她将能够看到所有可选择的项目,如下图:

在这里你可以看到我已经高亮了一部分,那部分是 Expandable listView。问题是,当我滚动可扩展列表时,我希望整个页面向上滚动,而不仅仅是可扩展列表,当我向任一方向滚动时,整个页面都是滚动的。

这是我的 XML 代码:

<LinearLayout 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:fitsSystemWindows="true"
android:orientation="vertical"
tools:context=".UI_Activity.RestaurantDetail">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <ImageButton
            android:id="@+id/RestaurantBackKey"
            android:layout_marginTop="10dp"
            android:layout_width="40dp"
            android:layout_marginStart="6dp"
            android:layout_height="30dp"
            android:gravity="center"
            android:background="?attr/selectableItemBackground"
            app:srcCompat="@drawable/ic_back_key"
            android:textStyle="bold"
            />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:padding="5dp"
            android:textSize="20sp"
            android:textStyle="bold"
            android:layout_marginEnd="52dp"
            android:layout_marginTop="5dp"
            android:text="@string/app_name"/>

    </LinearLayout>

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

        <androidx.cardview.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="250dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="5dp"
            android:layout_marginEnd="8dp"
            android:layout_marginBottom="8dp"
            app:cardCornerRadius="13dp">

            <ImageView
                android:id="@+id/RestaurantImage"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="centerCrop" />

        </androidx.cardview.widget.CardView>

        <TextView
            android:id="@+id/RestaurantName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:padding="5dp"
            android:text="RestaurantName"
            android:textSize="20sp"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/RestaurantTheme"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:padding="5dp"
            android:text=" This shop is based on the real thing"
            android:textSize="15sp"
            android:textStyle="italic" />

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:orientation="horizontal">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="8dp"
                android:layout_marginStart="5dp"
                android:text="Offers"
                android:textSize="15sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/OfferAvailability"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_marginEnd="10dp"
                android:clickable="true"
                android:focusable="true"
                android:padding="8dp"
                android:text="No Offers %"
                android:textColor="#9BA176"
                android:textSize="15sp"
                android:textStyle="bold" />

        </RelativeLayout>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Menu Item"
            android:gravity="center"
            android:textSize="18sp"
            android:padding="5dp"/>

    </LinearLayout>

    <ExpandableListView
        android:id="@+id/RestaurantItemList"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:footerDividersEnabled="false"
        android:headerDividersEnabled="false"
        android:smoothScrollbar="false" />

</LinearLayout>

谁能告诉我要进行哪些更改或哪种布局,或者我必须对现有代码进行哪些更新?

我想要的是,当我滚动可扩展列表视图时,我希望整个显示随之滚动。

提前谢谢你

【问题讨论】:

    标签: android scrollview expandablelistview android-nestedscrollview


    【解决方案1】:

    我能够通过为 ExpandableListView 创建一个自定义类来解决它。我在哪里进行了一些更改,最后我能够实现我一直在寻找的结果,谢谢。

    你可以参考这个链接:here

    【讨论】:

      【解决方案2】:

      您可能应该将整个布局包装在 NestedScrollView 中。

      【讨论】:

      • 什么不起作用?你试过these workarounds吗?
      • 当我使用 NestedScrollView 时,可扩展列表视图消失了!我的意思是在布局中找不到它!
      【解决方案3】:

      将整个布局放在ScrollView 中,这将使所有内容都可以滚动。

      【讨论】:

      • 如果我将整个布局放在 ScrollView 中,那么 Expandable 列表视图将获得 Wrapped 高度!即使我使用匹配父级。我也试过了
      猜你喜欢
      • 2019-04-20
      • 2019-03-05
      • 1970-01-01
      • 1970-01-01
      • 2021-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多