在带有TabLayout的片段中滚动视图,并且视图分页器不滚动 [英] Scroll view inside a fragment with tablayout and view pager not scrolling

查看:58
本文介绍了在带有TabLayout的片段中滚动视图,并且视图分页器不滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这个问题已经被问过很多次了,但是我几乎浏览了所有内容,但是片段中的滚动视图根本没有滚动.我尝试了许多解决方案,但没有一个起作用.请帮忙.谢谢你.这是我的xml文件:主要xml文件:

I know this question has been asked many times but i have looked through almost everything but my scroll view inside a fragment is not scrolling at all. I have tried many solutions but none of them are working. Please help. Thank you. Here are my xml files: Main xml file:

<?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:id="@+id/activity_flame_photometry"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.india.chemistry.flame_photometry">

    <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.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                app:layout_scrollFlags="scroll|enterAlways"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

            <android.support.design.widget.TabLayout
                android:id="@+id/tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:tabMode="fixed"
                app:tabGravity="fill"/>
        </android.support.design.widget.AppBarLayout>

        <android.support.v4.view.ViewPager
            android:id="@+id/viewpager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"  />
    </android.support.design.widget.CoordinatorLayout>


</RelativeLayout>

包含滚动视图的片段文件:

Fragment file that contains the scroll view:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fillViewport="true"
    tools:context="com.example.india.chemistry.flame_formula">

    <!-- TODO: Update blank fragment layout -->
    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:isScrollContainer="false">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/flameHeader"
            android:text="@string/flameHheader"
            android:textAppearance="@style/TextAppearance.AppCompat"
             />

        <TextView

            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/flameHeader"
            android:layout_marginTop="34dp"
            android:id="@+id/nacl_100cm"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true"
            android:text="@string/nacl_100cm"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true" />

        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ems="5"
            android:layout_below="@+id/nacl_100cm"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_marginTop="10dp"
            android:id="@+id/nacl_100_input"
            android:inputType="numberSigned|numberDecimal"
            android:hint="(W)g" />

        <TextView
            android:text="@string/nacl_1cm"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/nacl_100_input"
            android:layout_marginTop="10dp"
            android:id="@+id/nacl_1cm"
            android:padding="5dp"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:inputType="textPersonName|numberSigned|numberDecimal"
            android:text=""

            android:layout_below="@+id/nacl_100_input"
            android:layout_toRightOf="@id/nacl_1cm"
            android:padding="5dp"
            android:id="@+id/nacl_1cm_result"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true"
            android:layout_alignBottom="@+id/nacl_1cm" />

        <TextView
            android:text="@string/mol_weights_nacl"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/nacl_1cm"
            android:layout_marginTop="10dp"
            android:id="@+id/mol_weights_nacl"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true" />

        <TextView
            android:text="@string/mol_weights_kcl"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/mol_weights_nacl"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_marginTop="10dp"
            android:id="@+id/mol_weights_kcl"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true" />

        <TableLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/mol_weights_kcl"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_marginTop="25dp"
            >

            <TableRow
                >
                <TextView
                    android:id="@+id/srno_header"
                    android:padding="5dp"
                    android:text="Sl.\nno"
                   />
                <TextView
                    android:id="@+id/nacl_volume"
                    android:padding="5dp"
                    android:text="@string/nacl_volume"
                    />
                <TextView
                    android:id="@+id/weight_sodium"
                    android:padding="5dp"
                    android:text="Sodium \nweight"
                    />
                <TextView
                    android:id="@+id/flame_reading_1"
                    android:padding="5dp"
                    android:text="@string/flame_reading"
                    />
                <TextView
                    android:id="@+id/weight_sodium_2"
                    android:padding="5dp"
                    android:text="Sodium\nweight"/>
                <TextView
                    android:id="@+id/flame_reading_2"
                    android:padding="5dp"
                    android:text="@string/flame_reading"/>
            </TableRow>
            <TableRow>
                <TextView
                    android:id="@+id/slno1"
                    android:padding="5dp"
                    android:text="1"
                    />
                <TextView
                    android:id="@+id/volume1"
                    android:padding="5dp"
                    android:text="@string/volume1"/>
            </TableRow>
            <TableRow>
                <TextView
                    android:id="@+id/slno2"
                    android:padding="5dp"
                    android:text="1"
                    />
                <TextView
                    android:id="@+id/volume2"
                    android:padding="5dp"
                    android:text="@string/volume2"/>
            </TableRow>
            <TableRow>
                <TextView
                    android:id="@+id/slno3"
                    android:padding="5dp"
                    android:text="1"
                    />
                <TextView
                    android:id="@+id/volume3"
                    android:padding="5dp"
                    android:text="@string/volume3"/>
            </TableRow>
            <TableRow>
                <TextView
                    android:id="@+id/slno4"
                    android:padding="5dp"
                    android:text="1"
                    />
                <TextView
                    android:id="@+id/volume4"
                    android:padding="5dp"
                    android:text="@string/volume4"/>

            </TableRow>
            <TableRow>
                <TextView
                    android:id="@+id/slno5"
                    android:padding="5dp"
                    android:text="1"
                    />
                <TextView
                    android:id="@+id/volume5"
                    android:padding="5dp"
                    android:text="@string/volume5"/>
            </TableRow>


        </TableLayout>
    </RelativeLayout>


</ScrollView>

推荐答案

此选项对我有用.

活动布局

<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:background="@color/white">

<android.support.design.widget.AppBarLayout
    android:id="@+id/main.appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">
        <android.support.v7.widget.Toolbar></android.support.v7.widget.Toolbar>
        /*this toolbar not apply*/
</android.support.design.widget.AppBarLayout>
<ViewPager
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">
</ViewPager>
</android.support.design.widget.CoordinatorLayout>

片段布局

<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin">
        /**other elements here**/
</LinearLayout>
</android.support.v4.widget.NestedScrollView>

这篇关于在带有TabLayout的片段中滚动视图,并且视图分页器不滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆