Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/199.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 滚动活动中的视差_Android_Xml_Scroll_Parallax - Fatal编程技术网

Android 滚动活动中的视差

Android 滚动活动中的视差,android,xml,scroll,parallax,Android,Xml,Scroll,Parallax,我需要将activity_scrolling.xml中的图像与content_scrolling.xml的内容进行视差。我已经使用包含了这些内容。我在这里使用的操作栏是淡入淡出的。我还附上了一张截图 下面是activity_scrolling.xml的代码 <?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.CoordinatorLayout xmlns:android="http:

我需要将activity_scrolling.xml中的图像与content_scrolling.xml的内容进行视差。我已经使用
包含了这些内容。我在这里使用的操作栏是淡入淡出的。我还附上了一张截图 下面是activity_scrolling.xml的代码

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".ScrollingActivity">


    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:fitsSystemWindows="true"
        android:layout_height="300dp"
        android:background="@drawable/pweek1"

        android:layout_width="match_parent"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/toolbar_layout"
            android:fitsSystemWindows="true"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:contentScrim="?attr/colorPrimary">
            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_height="?attr/actionBarSize"
                android:layout_width="match_parent"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/AppTheme.PopupOverlay" />

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





    <include layout="@layout/content_scrolling" />




</android.support.design.widget.CoordinatorLayout>
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:showIn="@layout/activity_scrolling" android:layout_width="match_parent"
    android:layout_height="match_parent" tools:context=".ScrollingActivity">
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">




    <TextView
        android:id="@+id/textView4"
        android:layout_width="match_parent"
        android:text="INGREDIENTS"
        android:layout_height="wrap_content"
        android:paddingLeft="20dp"
        android:paddingRight="15dp"
        android:gravity="left"
        />

    <LinearLayout
        android:layout_width="match_parent"
        android:id="@+id/ingredients"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView4"
        android:layout_marginTop="15dp"
        >
        <ListView
            android:id="@+id/inglist"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:divider="#DDDDDD"
            />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/nutfacts"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/ingredients"
        android:orientation="horizontal"
        android:layout_marginBottom="10dp"
        android:paddingTop="5dp"
        android:paddingBottom="5dp"
        android:weightSum="4">

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:background="#8b1e1e"
        android:layout_height="100dp"
        android:layout_weight="1"/>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:layout_weight="1"
        android:weightSum="2" >

        <TextView
            android:id="@+id/caltext"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:textColor="#000000"
            android:gravity="center"
            android:textSize="20dp"
            android:layout_weight="1"/>

        <TextView
            android:id="@+id/caltext2"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:textColor="#000000"
            android:gravity="center"
            android:layout_weight="1"/>

    </LinearLayout>


    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="match_parent"

        android:background="#8b1e1e"
        android:layout_height="100dp"
        android:layout_weight="1"/>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:layout_weight="1"
        android:weightSum="2"
        android:layout_marginRight="10dp">

        <TextView
            android:id="@+id/sertext"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:textSize="20dp"
            android:textColor="#000000"
            android:layout_weight="1"/>

        <TextView
            android:id="@+id/sertext2"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:textColor="#000000"
            android:gravity="center"
            android:layout_weight="1"/>

    </LinearLayout>
    </LinearLayout>

    <TextView
        android:id="@+id/textView5"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/nutfacts"
        android:gravity="left"
        android:text="Direction Of Use"
        android:paddingLeft="20dp"
        android:paddingRight="15dp"
        android:layout_marginTop="15dp"
        android:layout_marginBottom="15dp"
        />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="#000000"
        android:text="@string/large_text"
        android:layout_below="@+id/textView5"
        android:paddingLeft="15dp"
        android:paddingRight="15dp"
        />


</RelativeLayout>
</android.support.v4.widget.NestedScrollView>

这是content_scrolling.xml的代码

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".ScrollingActivity">


    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:fitsSystemWindows="true"
        android:layout_height="300dp"
        android:background="@drawable/pweek1"

        android:layout_width="match_parent"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/toolbar_layout"
            android:fitsSystemWindows="true"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:contentScrim="?attr/colorPrimary">
            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_height="?attr/actionBarSize"
                android:layout_width="match_parent"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/AppTheme.PopupOverlay" />

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





    <include layout="@layout/content_scrolling" />




</android.support.design.widget.CoordinatorLayout>
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:showIn="@layout/activity_scrolling" android:layout_width="match_parent"
    android:layout_height="match_parent" tools:context=".ScrollingActivity">
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">




    <TextView
        android:id="@+id/textView4"
        android:layout_width="match_parent"
        android:text="INGREDIENTS"
        android:layout_height="wrap_content"
        android:paddingLeft="20dp"
        android:paddingRight="15dp"
        android:gravity="left"
        />

    <LinearLayout
        android:layout_width="match_parent"
        android:id="@+id/ingredients"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView4"
        android:layout_marginTop="15dp"
        >
        <ListView
            android:id="@+id/inglist"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:divider="#DDDDDD"
            />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/nutfacts"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/ingredients"
        android:orientation="horizontal"
        android:layout_marginBottom="10dp"
        android:paddingTop="5dp"
        android:paddingBottom="5dp"
        android:weightSum="4">

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:background="#8b1e1e"
        android:layout_height="100dp"
        android:layout_weight="1"/>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:layout_weight="1"
        android:weightSum="2" >

        <TextView
            android:id="@+id/caltext"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:textColor="#000000"
            android:gravity="center"
            android:textSize="20dp"
            android:layout_weight="1"/>

        <TextView
            android:id="@+id/caltext2"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:textColor="#000000"
            android:gravity="center"
            android:layout_weight="1"/>

    </LinearLayout>


    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="match_parent"

        android:background="#8b1e1e"
        android:layout_height="100dp"
        android:layout_weight="1"/>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:layout_weight="1"
        android:weightSum="2"
        android:layout_marginRight="10dp">

        <TextView
            android:id="@+id/sertext"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:textSize="20dp"
            android:textColor="#000000"
            android:layout_weight="1"/>

        <TextView
            android:id="@+id/sertext2"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:textColor="#000000"
            android:gravity="center"
            android:layout_weight="1"/>

    </LinearLayout>
    </LinearLayout>

    <TextView
        android:id="@+id/textView5"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/nutfacts"
        android:gravity="left"
        android:text="Direction Of Use"
        android:paddingLeft="20dp"
        android:paddingRight="15dp"
        android:layout_marginTop="15dp"
        android:layout_marginBottom="15dp"
        />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="#000000"
        android:text="@string/large_text"
        android:layout_below="@+id/textView5"
        android:paddingLeft="15dp"
        android:paddingRight="15dp"
        />


</RelativeLayout>
</android.support.v4.widget.NestedScrollView>


你的问题是什么?问题是当我使用视差库时,操作栏就消失了。你能告诉我在哪里添加库吗?我使用的是nirhart/ParallaxScroll(我使用的是谷歌正版的Android设计支持库。请参阅: