ScrollingActivity中的视差android

时间:2015-11-12 14:37:09

标签: android xml scroll parallax

我需要使用content_scrolling.xml的内容在activity_scrolling.xml中对我的图像进行视差处理。我已经使用<include layout="@layout/content_scrolling" />包含了内容。我在这里使用的操作栏正在消失。我还包括了一个屏幕截图img 这是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>

内容代码of content_scrolling.xml

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

0 个答案:

没有答案