在同一屏幕上呈现滚动视图和列表视图

时间:2017-01-09 07:59:14

标签: android xml android-layout listview android-scrollview

  • 我在渲染滚动视图时遇到问题,我想要一个列表视图。
  • 我想要一个滚动视图,在其中我将添加图像视图和文本视图,或者可能是其他UI元素。
  • 在此滚动视图下方,我想要一个列表视图。

但是当我这样做时,列表视图和滚动视图重叠,或者仅渲染滚动视图。

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>

2 个答案:

答案 0 :(得分:1)

在同一布局中拥有多个基于滚动的视图始终是一个问题。您可以使用嵌套的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>
layout_behaviour上的

For more和嵌套滚动。

答案 1 :(得分:0)

将相对布局更改为线性布局将解决此问题.. !!

相关问题