问题描述
我正在为我的餐厅制作一个应用程序,当用户进入餐厅页面时,他或她将能够看到所有可选项目,如下图所示:
在这里您可以看到我突出显示了一部分,而该部分是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>
任何人都可以告诉我要进行哪些更改,布局或在现有代码中进行任何更新吗?
我想要的是,当我滚动可扩展列表视图时,我希望整个显示都随之滚动。
提前谢谢
解决方法
我能够通过为ExpandableListView创建一个自定义类来解决它。在进行了一些更改之后,终于能够实现我一直在寻找的结果,谢谢。
您可以参考以下链接:here
,您可能应该将整个布局包装在NestedScrollView
中。
将整个布局放在blob
内,这将使所有内容均可滚动。