0

是否需要做任何事情来启用滚动视图内的滚动?另外,滚动视图中可以包含哪些元素?

这是相关的代码。第一个片段中的滚动视图似乎不起作用。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/bg_gray"
    android:orientation="vertical" >

    <include android:id="@+id/header"
        android:layout_alignParentTop="true"
        android:layout_width="wrap_content"
        android:layout_height = "wrap_content"
        layout="@layout/header_layout" />

    <LinearLayout android:id="@+id/llFooter"
        android:layout_width = "fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="vertical" >

        <Button android:id="@+id/datePick"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal|center_vertical"
            android:text="@string/confirmTime"
            android:onClick="timeSelect" />

    </LinearLayout>

    <ScrollView android:id="@+id/calView"
        android:layout_below="@id/header"
        android:layout_above="@id/llFooter"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:fillViewport="true" >

        <include android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            layout="@layout/calendar_day_view" />

    </ScrollView>

</RelativeLayout>

日历日视图:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:baselineAligned="false"
    android:background="@android:color/white"
    android:orientation="horizontal" >

    <RelativeLayout android:layout_width="0px"
        android:layout_height="fill_parent"
        android:layout_weight="1">

        <TextView android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/eightAM" />

        <TextView android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/nineAM"
            android:translationY="60dp" />

        <TextView android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/tenAM"
            android:translationY="120dp" />

        <TextView android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/elevenAM"
            android:translationY="180dp" />

        <TextView android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/twelvePM"
            android:translationY="240dp" />

        <TextView android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/onePM"
            android:translationY="300dp" />

        <TextView android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/twoPM"
            android:translationY="360dp" />

        <TextView android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/threePM"
            android:translationY="420dp" />

        <TextView android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/fourPM"
            android:translationY="480dp" />

        <TextView android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/fivePM"
            android:translationY="540dp" />

        <TextView android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/sixPM"
            android:translationY="600dp" />

    </RelativeLayout>

    <include android:layout_width="0px"
        android:layout_height="fill_parent"
        android:layout_weight="3"
        layout="@layout/calendar_horizontal_delims" />"

</LinearLayout>

和 calendar_horizo​​ntal_delims.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <View android:translationY="60dip"
        android:layout_width="fill_parent"
        android:layout_height="1dip"
        android:background="#000000"/>

    <View android:translationY="120dip"
        android:layout_width="fill_parent"
        android:layout_height="1dip"
        android:background="#000000"/>

    <View android:translationY="180dip"
        android:layout_width="fill_parent"
        android:layout_height="1dip"
        android:background="#000000"/>

    <View android:translationY="240dip"
        android:layout_width="fill_parent"
        android:layout_height="1dip"
        android:background="#000000"/>

    <View android:translationY="300dip"
        android:layout_width="fill_parent"
        android:layout_height="1dip"
        android:background="#000000"/>

    <View android:translationY="360dip"
        android:layout_width="fill_parent"
        android:layout_height="1dip"
        android:background="#000000"/>

    <View android:translationY="420dip"
        android:layout_width="fill_parent"
        android:layout_height="1dip"
        android:background="#000000"/>

    <View android:translationY="480dip"
        android:layout_width="fill_parent"
        android:layout_height="1dip"
        android:background="#000000"/>

    <View android:translationY="540dip"
        android:layout_width="fill_parent"
        android:layout_height="1dip"
        android:background="#000000"/>

    <View android:translationY="600dip"
        android:layout_width="fill_parent"
        android:layout_height="1dip"
        android:background="#000000"/>

</LinearLayout>
4

2 回答 2

0

在 ScrollView 的内容超过屏幕大小之前,ScrollView 什么都不做,此时 ScrollView 内的任何内容都可以自动滚动。几乎任何东西都可以进入 ScrollView,除了默认可滚动的东西,例如 ListView。

您可能想查看 ScrollView 文档:http: //developer.android.com/reference/android/widget/ScrollView.html

于 2013-11-07T22:43:31.357 回答
0

我认为问题出translationY在您的 calendar_day_view 中的属性中。老实说,这是我第一次看到这种对齐元素的方式:)

所以发生的事情是你所有的 TextViews 基本上都布置在同一个Y位置(因为它们被放置在里面RelativeLayout)。它们只是在视觉上垂直翻译。这就是为什么从布局的角度来看,对于 ScrollView,您的文本视图的总高度不超过 scrollView 的高度,所以这就是它们不滚动的原因。

你必须重新调整你的对齐方式。首先,将LinearLayout方向更改为vertical并删除兄弟RelativeLayout,因此您所有的文本视图都放置在垂直 LinearLayout内部并尝试使用marginTop属性而不是translationY

这基本上就是你的calendar_day_view.xml样子:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:baselineAligned="false"
    android:background="@android:color/white"
    android:orientation="vertical" >

    <TextView android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/eightAM" />

    <TextView android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/nineAM"
        android:layout_marginTop="60dp" />

    <TextView android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/tenAM"
        android:layout_marginTop="60dp" />

    <TextView android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/elevenAM"
        android:layout_marginTop="60dp" />

    <TextView android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/twelvePM"
        android:layout_marginTop="60dp" />

    <TextView android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/onePM"
        android:layout_marginTop="60dp" />

    <TextView android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/twoPM"
        android:layout_marginTop="60dp" />

    <TextView android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/threePM"
        android:layout_marginTop="60dp" />

    <TextView android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/fourPM"
        android:layout_marginTop="60dp" />

    <TextView android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/fivePM"
        android:layout_marginTop="60dp" />

    <TextView android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/sixPM"
        android:layout_marginTop="60dp" />

    <include android:layout_width="0px"
        android:layout_height="fill_parent"
        android:layout_weight="3"
        layout="@layout/calendar_horizontal_delims" />"

</LinearLayout>

需要做类似的改变calendar_horizontal_delims.xml

于 2013-11-08T23:09:27.393 回答