布局中的Android滚动视图 - 大型横向不滚动?

时间:2017-08-04 11:41:31

标签: android android-layout android-fragments relativelayout android-scrollview

我的滚动视图不会使我的布局滚动。 scrollview不滚动的原因是什么?

这是我的xml布局文件。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/top_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@color/white">
<ScrollView 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:scrollbars="vertical"
    android:fillViewport="true">

    <android.support.percent.PercentRelativeLayout xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:padding="5dp">

        <TextView
            android:id="@+id/topPanel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:background="@drawable/borders"
            android:gravity="center"
            android:padding="10dp"
            android:text="General Details"
            android:textAppearance="?android:textAppearanceLarge"
            android:textStyle="bold"
            app:layout_marginTopPercent="1%" />

        <TextView
            android:id="@+id/caption_case"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_below="@+id/topPanel"

            android:text="Case No."
            android:textAppearance="?android:textAppearanceLarge"
            android:textColor="@android:color/black"
            android:textStyle="bold"
            app:layout_marginTopPercent="1%"
            app:layout_widthPercent="50%" />

        <TextView
            android:id="@+id/caption_visit_date"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_below="@+id/topPanel"
            android:layout_toRightOf="@+id/caption_case"
            android:text="Date Of Visit"
            android:textAppearance="?android:textAppearanceLarge"
            android:textColor="@android:color/black"
            android:textStyle="bold"
            app:layout_marginStartPercent="1%"
            app:layout_marginTopPercent="1%"
            app:layout_widthPercent="50%" />

        <EditText
            android:id="@+id/case_number"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_below="@+id/caption_case"
            android:background="@drawable/borders_grey"
            android:hint="Enter Case Number"
            android:imeOptions="flagNoExtractUi"
            android:maxLines="1"
            android:minHeight="50dp"
            android:padding="3dp"
            android:singleLine="true"
            android:textColor="@android:color/black"
            android:textColorHighlight="@android:color/black"
            android:textCursorDrawable="@drawable/cursor_color"
            app:layout_widthPercent="50%" />

        <EditText
            android:id="@+id/visit_date"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_below="@+id/caption_visit_date"

            android:layout_toRightOf="@+id/case_number"
            android:background="@drawable/borders_grey"
            android:hint="Enter Date"
            android:imeOptions="flagNoExtractUi"
            android:inputType="none"
            android:maxLines="1"
            android:minHeight="50dp"
            android:padding="3dp"
            android:singleLine="true"
            android:textColor="@android:color/black"
            android:textColorHighlight="@android:color/black"
            android:textCursorDrawable="@drawable/cursor_color"
            app:layout_marginStartPercent="1%"
            app:layout_widthPercent="50%" />

        <TextView
            android:id="@+id/caption_district"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_below="@+id/visit_date"
            android:text="District"
            android:textAppearance="?android:textAppearanceLarge"
            android:textColor="@android:color/black"
            android:textStyle="bold"
            app:layout_marginTopPercent="1%"
            app:layout_widthPercent="50%" />

        <TextView
            android:id="@+id/caption_block"
            android:layout_width="0dp"
            android:layout_below="@+id/visit_date"
            android:layout_toRightOf="@+id/caption_district"
            android:text="Block"
            android:textAppearance="?android:textAppearanceLarge"
            android:textColor="@android:color/black"
            android:textStyle="bold"
            app:layout_marginStartPercent="1%"
            app:layout_marginTopPercent="1%"
            app:layout_widthPercent="50%" />

        <EditText
            android:id="@+id/district"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_below="@+id/caption_district"
            android:background="@drawable/borders_grey"
            android:hint="Enter District"
            android:imeOptions="flagNoExtractUi"
            android:inputType="none"
            android:maxLines="1"
            android:minHeight="50dp"
            android:padding="3dp"
            android:singleLine="true"
            android:textColor="@android:color/black"
            android:textColorHighlight="@android:color/black"
            android:textCursorDrawable="@drawable/cursor_color"
            app:layout_widthPercent="50%" />

        <EditText
            android:id="@+id/block"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_below="@+id/caption_district"
            android:layout_toRightOf="@+id/district"
            android:background="@drawable/borders_grey"
            android:hint="Enter Block"
            android:imeOptions="flagNoExtractUi"
            android:inputType="none"
            android:maxLines="1"
            android:minHeight="50dp"
            android:padding="3dp"
            android:singleLine="true"
            android:textColor="@android:color/black"
            android:textColorHighlight="@android:color/black"
            android:textCursorDrawable="@drawable/cursor_color"
            app:layout_marginStartPercent="1%"
            app:layout_widthPercent="50%" />

        <TextView
            android:id="@+id/caption_school"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_below="@+id/block"
            android:text="School Name"
            android:textAppearance="?android:textAppearanceLarge"
            android:textColor="@android:color/black"
            android:textStyle="bold"
            app:layout_marginTopPercent="1%"
            app:layout_widthPercent="50%" />

        <TextView
            android:id="@+id/caption_school_type"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_below="@+id/block"
            android:layout_toRightOf="@id/caption_school"
            android:text="School Type"
            android:textAppearance="?android:textAppearanceLarge"
            android:textColor="@android:color/black"
            android:textStyle="bold"
            app:layout_marginStartPercent="1%"
            app:layout_marginTopPercent="1%"
            app:layout_widthPercent="50%" />

        <EditText
            android:id="@+id/school_name"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_below="@+id/caption_school"
            android:background="@drawable/borders_grey"
            android:hint="Enter Block"
            android:imeOptions="flagNoExtractUi"
            android:inputType="none"
            android:maxLines="1"
            android:minHeight="50dp"
            android:padding="3dp"
            android:singleLine="true"
            android:textColor="@android:color/black"
            android:textColorHighlight="@android:color/black"
            android:textCursorDrawable="@drawable/cursor_color"
            app:layout_widthPercent="50%" />

        <EditText
            android:id="@+id/school_type"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_below="@+id/caption_school_type"
            android:layout_toRightOf="@id/school_name"
            android:background="@drawable/borders_grey"
            android:hint="Enter School Type"
            android:imeOptions="flagNoExtractUi"
            android:maxLines="1"
            android:minHeight="50dp"
            android:padding="3dp"
            android:singleLine="true"
            android:textColor="@android:color/black"
            android:textColorHighlight="@android:color/black"
            android:textCursorDrawable="@drawable/cursor_color"
            app:layout_marginStartPercent="1%"
            app:layout_widthPercent="50%" />

        <TextView
            android:id="@+id/caption_from_time"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_below="@+id/school_name"
            android:text="From Time"
            android:textAppearance="?android:textAppearanceLarge"
            android:textColor="@android:color/black"
            android:textStyle="bold"
            app:layout_marginTopPercent="1%"
            app:layout_widthPercent="50%" />

        <TextView
            android:id="@+id/caption_to_time"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_below="@+id/school_name"
            android:layout_toRightOf="@+id/caption_from_time"
            android:text="To Time"
            android:textAppearance="?android:textAppearanceLarge"
            android:textColor="@android:color/black"
            android:textStyle="bold"
            app:layout_marginStartPercent="1%"
            app:layout_marginTopPercent="1%"
            app:layout_widthPercent="50%" />

        <EditText
            android:id="@+id/from_time"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_below="@+id/caption_from_time"
            android:background="@drawable/borders_grey"
            android:hint="Enter Start Time"
            android:imeOptions="flagNoExtractUi"
            android:inputType="none"
            android:maxLines="1"
            android:minHeight="50dp"
            android:padding="3dp"
            android:singleLine="true"
            android:textColor="@android:color/black"
            android:textColorHighlight="@android:color/black"
            android:textCursorDrawable="@drawable/cursor_color"
            app:layout_widthPercent="50%" />

        <EditText
            android:id="@+id/to_time"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_below="@+id/caption_to_time"
            android:layout_toRightOf="@id/from_time"
            android:background="@drawable/borders_grey"
            android:hint="Enter End Time"
            android:imeOptions="flagNoExtractUi"
            android:inputType="none"
            android:maxLines="1"
            android:minHeight="50dp"
            android:padding="3dp"
            android:singleLine="true"
            android:textColor="@android:color/black"
            android:textColorHighlight="@android:color/black"
            android:textCursorDrawable="@drawable/cursor_color"
            app:layout_marginStartPercent="1%"
            app:layout_widthPercent="50%" />

        <TextView
            android:id="@+id/caption_team_incharge"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_below="@+id/from_time"
            android:text="Inspection Team Incharge Name/Designation"
            android:textAppearance="?android:textAppearanceLarge"
            android:textColor="@android:color/black"
            android:textStyle="bold"
            app:layout_marginTopPercent="1%"
            app:layout_widthPercent="50%" />

        <TextView
            android:id="@+id/caption_team_incharge_phone"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_below="@+id/to_time"
            android:layout_toRightOf="@+id/caption_team_incharge"
            android:text="Inspection Team Incharge Mobile No."
            android:textAppearance="?android:textAppearanceLarge"
            android:textColor="@android:color/black"
            android:textStyle="bold"
            app:layout_marginStartPercent="1%"
            app:layout_marginTopPercent="1%"
            app:layout_widthPercent="50%" />

        <EditText
            android:id="@+id/team_incharge_name"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_below="@+id/caption_team_incharge"
            android:background="@drawable/borders_grey"

            android:hint="Enter Team Incharge Name/Designation"
            android:imeOptions="flagNoExtractUi"
            android:maxLines="2"
            android:minHeight="50dp"
            android:padding="3dp"
            android:textColor="@android:color/black"
            android:textColorHighlight="@android:color/black"
            android:textCursorDrawable="@drawable/cursor_color"
            app:layout_widthPercent="50%" />

        <EditText
            android:id="@+id/team_incharge_mobile"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_below="@+id/caption_team_incharge_phone"
            android:layout_toRightOf="@id/team_incharge_name"
            android:background="@drawable/borders_grey"
            android:hint="Enter Team Incharge Mobile Number"
            android:imeOptions="flagNoExtractUi"
            android:maxLines="1"
            android:minHeight="50dp"
            android:padding="3dp"
            android:singleLine="true"
            android:textColor="@android:color/black"
            android:textColorHighlight="@android:color/black"
            android:textCursorDrawable="@drawable/cursor_color"
            app:layout_marginStartPercent="1%"
            app:layout_widthPercent="50%" />

        <TextView
            android:id="@+id/caption_school_incharge_name"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_below="@+id/team_incharge_mobile"
            android:text="Name Of School Head"
            android:textAppearance="?android:textAppearanceLarge"
            android:textColor="@android:color/black"
            android:textStyle="bold"
            app:layout_marginTopPercent="1%"
            app:layout_widthPercent="50%" />

        <TextView
            android:id="@+id/caption_school_incharge_phone"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_below="@+id/team_incharge_mobile"
            android:layout_toRightOf="@id/caption_school_incharge_name"
            android:text="School Head Mobile No."
            android:textAppearance="?android:textAppearanceLarge"
            android:textColor="@android:color/black"
            android:textStyle="bold"
            app:layout_marginStartPercent="1%"
            app:layout_marginTopPercent="1%"
            app:layout_widthPercent="50%" />

        <EditText
            android:id="@+id/school_head_name"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_below="@+id/caption_school_incharge_name"
            android:background="@drawable/borders_grey"
            android:hint="Enter School Head Name"
            android:imeOptions="flagNoExtractUi"
            android:maxLines="1"
            android:minHeight="50dp"
            android:padding="3dp"
            android:singleLine="true"
            android:textColor="@android:color/black"
            android:textColorHighlight="@android:color/black"
            android:textCursorDrawable="@drawable/cursor_color"
            app:layout_widthPercent="50%" />

        <EditText
            android:id="@+id/school_head_mobile"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_below="@+id/caption_school_incharge_phone"
            android:layout_toRightOf="@+id/school_head_name"
            android:background="@drawable/borders_grey"
            android:hint="Enter School Head Mobile Number"
            android:imeOptions="flagNoExtractUi"
            android:maxLines="1"
            android:minHeight="50dp"
            android:padding="3dp"
            android:singleLine="true"
            android:textColor="@android:color/black"
            android:textColorHighlight="@android:color/black"
            android:textCursorDrawable="@drawable/cursor_color"
            app:layout_marginStartPercent="1%"
            app:layout_widthPercent="50%" />


    </android.support.percent.PercentRelativeLayout>
</ScrollView>
    </LinearLayout>

1 个答案:

答案 0 :(得分:0)

这是因为caption_block视图中缺少某个属性,不知何故会弄乱你的滚动视图。

<TextView
    android:id="@+id/caption_block"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_below="@+id/visit_date"
    android:layout_toRightOf="@+id/caption_district"
    android:text="Block"
    android:textAppearance="?android:textAppearanceLarge"
    android:textColor="@android:color/black"
    android:textStyle="bold"
    app:layout_marginStartPercent="1%"
    app:layout_marginTopPercent="1%"
    app:layout_widthPercent="50%" />

layout_height属性设置为wrap_content,您就可以了。