填写viewPort后,ScrollView也不会滚动

时间:2015-12-11 04:07:20

标签: android android-layout scrollview

我有一个问题,我的屏幕甚至不会滚动,我不知道为什么。我将需要滚动的所有内容包装成ScrollView并将LinearLayout作为其单个子项。我还设置了fillViewPorts=true并填满了布局的整个空间。我不明白我做错了什么。谁能帮助我指出正确的方向?这是我的代码:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent" android:fitsSystemWindows="true"
    xmlns:fresco="http://schemas.android.com/tools"
    android:id="@+id/comments_coordinator_layout">

    <android.support.design.widget.AppBarLayout
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/comments_appbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </android.support.design.widget.AppBarLayout>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:layout_below="@id/comments_coordinator_layout"
        android:fillViewport="true"
        >

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

            <RelativeLayout
                android:layout_marginTop="?attr/actionBarSize"
                android:id="@+id/view_post"
                android:layout_width="match_parent"
                android:paddingRight="5dp"
                android:paddingLeft="5dp"
                android:orientation="horizontal"
                android:layout_height="175dp"
                android:background="#e6e6e6">

                <com.facebook.drawee.view.SimpleDraweeView
                    android:layout_marginTop="15dp"
                    android:id="@+id/poster_picture"
                    android:layout_width="75dp"
                    android:layout_height="75dp"
                    android:layout_marginLeft="10dp"
                    fresco:placeholderImage="@mipmap/blank_prof_pic"
                    fresco:roundedCornerRadius="5dp"
                    />

                <TextView
                    android:layout_marginLeft="5dp"
                    android:layout_marginTop="15dp"
                    android:layout_toRightOf="@id/poster_picture"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="15sp"
                    android:textStyle="bold"
                    android:id="@+id/poster_name"/>

                <TextView
                    android:layout_alignParentRight="true"
                    android:layout_marginTop="15dp"
                    android:layout_toRightOf="@id/poster_name"
                    android:layout_marginLeft="5dp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="15sp"
                    android:id="@+id/post_date"/>

                <TextView
                    android:layout_marginLeft="5dp"
                    android:layout_toRightOf="@id/poster_picture"
                    android:layout_below="@id/poster_name"
                    android:textSize="20sp"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:id="@+id/view_status" />

            </RelativeLayout>

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <LinearLayout
                    android:orientation="vertical"
                    android:id="@+id/container_list"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_above="@+id/send_message">
                </LinearLayout>


                <LinearLayout
                    android:id="@+id/send_message"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:padding="5dp"
                    android:layout_alignParentBottom="true"
                    android:orientation="horizontal" >

                    <EditText
                        android:id="@+id/write_comment"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_vertical|center_horizontal"
                        android:layout_weight="5"
                        android:gravity="top|left"
                        android:hint="Comment back!"
                        android:inputType="textMultiLine"
                        android:scrollHorizontally="false" />

                    <Button
                        android:id="@+id/send_comment"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_vertical|center_horizontal"
                        android:gravity="center"
                        android:text="send"
                        android:textAppearance="?android:attr/textAppearanceMedium" />
                </LinearLayout>

            </RelativeLayout>

        </LinearLayout>


    </ScrollView>

</android.support.design.widget.CoordinatorLayout>

1 个答案:

答案 0 :(得分:1)

在CoordinatorLayout中使用时,ScrollView可能会出现问题。切换到NestedScrollView可能会解决您的问题。