简体   繁体   English

滚动视图内部线性布局不滚动

[英]Scrollview inside linear layout not scrolling

I'm trying to make a day view similar to Google Calendar but I can't seem to get my scrollview to scroll. 我正在尝试使日视图类似于Google日历,但似乎无法使滚动视图滚动。 My scrollview is located inside a linear layout. 我的滚动视图位于线性布局内。 I also have a button that needs to be below the scrollview. 我也有一个按钮需要位于滚动视图下方。 As a note both the button and the scrollview have a layout_weight associated with them. 注意,按钮和滚动视图均具有与之关联的layout_weight。

Here are the relevant snippets: 以下是相关片段:

<ScrollView android:layout_width="wrap_content"
    android:layout_height="0px" 
    android:layout_weight="6"
    android:fillViewport="true" >

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

</ScrollView>

calendar_day_view.xml: 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="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>

and calendar_horizontal_delims.xml: 和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>

Try This: 尝试这个:

<ScrollView
        android:layout_width="wrap_content"
        android:layout_height="match_parent">

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

</ScrollView>

I think you are misunderstanding the use of the ScrollView : 我认为您误解了ScrollView的用法:

ScrollView only supports vertical scrolling. For horizontal scrolling, use HorizontalScrollView.

More info: 更多信息:

ScrollView 滚动视图

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM