簡體   English   中英

滾動視圖內部線性布局不滾動

[英]Scrollview inside linear layout not scrolling

我正在嘗試使日視圖類似於Google日歷,但似乎無法使滾動視圖滾動。 我的滾動視圖位於線性布局內。 我也有一個按鈕需要位於滾動視圖下方。 注意,按鈕和滾動視圖均具有與之關聯的layout_weight。

以下是相關片段:

<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:

<?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>

嘗試這個:

<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>

我認為您誤解了ScrollView的用法:

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

更多信息:

滾動視圖

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM