gpt4 book ai didi

android - 在同一屏幕上呈现 ScrollView 和 ListView

转载 作者:数据小太阳 更新时间:2023-10-29 02:39:07 25 4
gpt4 key购买 nike

  • 我在呈现 ScrollView 时遇到问题,在 ScrollView 下方我想要一个 ListView 。
  • 我想要一个 ScrollView ,我将在其中添加 ImageView 和 TextView ,或者可能是其他 UI 元素。
  • 在此 ScrollView 下方,我想要一个 ListView 。

但是当我这样做时,要么 ListView 和 ScrollView 重叠,要么只渲染 ScrollView 。

XML 代码:Gist

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:id="@+id/content_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.dell.finalstartup.MainActivity"
tools:showIn="@layout/app_bar_main">

<ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />

<!-- For pic of the day -->
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content">

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

<LinearLayout
android:id="@+id/layout_PicOfTheDay"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pic of the day example layout"
android:textSize="22sp" />

<ImageView
android:id="@+id/picOfTheDay"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

</LinearLayout>

<!-- Grey Line -->
<View
android:layout_width="match_parent"
android:layout_height="@dimen/gray_line_width"
android:background="#c0c0c0" />

</LinearLayout>
</ScrollView>

<!-- For products -->
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/scrollView" />

</RelativeLayout>

最佳答案

在同一个布局中有多个基于滚动的 View 总是一个问题。您可以使用嵌套的 ScrollView ,它是 V4 库的一部分。

<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.v4.widget.NestedScrollView>

For more关于 layout_behaviour 和嵌套滚动。

关于android - 在同一屏幕上呈现 ScrollView 和 ListView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41543385/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com