2017-04-04 1 views
0

Ich möchte den Parallax-Effekt erhalten, der in viber profile/android contacts verwendet wird. Ich habe gesehen, dass es möglich ist, benutzerdefinierte Klasse zu verwenden, aber ist es möglich, es mit Koordinatenlayout zu tun?Wie man Parallaxen-Effekt wie ein Viber-Profil mit Koordinaten-Layout erzeugt

Edit 1: Ich habe das schon getan. preview Was ich mehr will, ist, dass das Profilbild die Hälfte der Höhe anfänglich zeigt und wenn wir den Bildschirm nach unten ziehen, um das volle Bild zu sehen und wenn wir das Bild wieder freigeben, kommen wir in den Anfangszustand (Halbbild).

+0

http://stackoverflow.com/questions/36659006/using-a-coordinatorlayout-to-collapse-a-full-screen-imageview-and-replace-it- wit –

Antwort

0

Sie können die folgenden Referenz aussehen:

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

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/main.appbar" 
     android:layout_width="match_parent" 
     android:layout_height="300dp" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
     android:fitsSystemWindows="true"> 

     <android.support.design.widget.CollapsingToolbarLayout 
      android:id="@+id/main.collapsing" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      app:layout_scrollFlags="scroll|exitUntilCollapsed" 
      android:fitsSystemWindows="true" 
      app:contentScrim="?attr/colorPrimary" 
      app:expandedTitleMarginStart="48dp" 
      app:expandedTitleMarginEnd="64dp"> 

      <ImageView 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:scaleType="centerCrop" 
       android:fitsSystemWindows="true" 
       android:src="@drawable/material_flat" 
       app:layout_collapseMode="parallax"/> 

      <android.support.v7.widget.Toolbar 
       android:id="@+id/main.toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="?attr/actionBarSize" 
       app:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
       app:layout_collapseMode="pin"/> 

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

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

    <android.support.v4.widget.NestedScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:textSize="20sp" 
      android:lineSpacingExtra="8dp" 
      android:text="@string/lorem" 
      android:padding="@dimen/activity_horizontal_margin"/> 
    </android.support.v4.widget.NestedScrollView> 

    <android.support.design.widget.FloatingActionButton 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:layout_margin="@dimen/activity_horizontal_margin" 
     android:src="@drawable/ic_comment_24dp" 
     app:layout_anchor="@id/main.appbar" 
     app:layout_anchorGravity="bottom|right|end"/> 
</android.support.design.widget.CoordinatorLayout> 

Preview Here

+0

Vielen Dank für Ihren Rat, eigentlich habe ich das schon selbst gemacht, was ich mehr will, ist ein Bildschirm zu implementieren, wo Benutzer Profilbild zeigen die Hälfte der Höhe und wenn wir den Bildschirm nach unten ziehen in der Lage, das vollständige Bild zu sehen und wenn wir freigeben wieder Bild kommen im Ausgangszustand (Halbbild). –

+0

Ok. Warum checkst du das dann nicht aus? [PullScrollView] (https://github.com/MarkMjw/PullScrollView). –

+0

https://github.com/saulmm/CoordinatorBehaviorBeispiel –

0

Das ist genau das brauchen Sie

http://www.androidauthority.com/using-coordinatorlayout-android-apps-703720/

<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="com.sample.foo.usingcoordinatorlayout.FabAndSnackbarActivity"> 

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/appBar" 
     android:layout_width="match_parent" 
     android:layout_height="300dp" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" 
     android:fitsSystemWindows="true"> 

     <android.support.design.widget.CollapsingToolbarLayout 
      android:id="@+id/collapsingToolbar" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      app:layout_scrollFlags="scroll|exitUntilCollapsed" 
      android:fitsSystemWindows="true" 
      app:contentScrim="?attr/colorPrimary" 
      app:expandedTitleMarginStart="48dp" 
      app:expandedTitleMarginEnd="64dp" 
      app:title="@string/collapsing_toolbar"> 

      <ImageView 
       android:id="@+id/toolbarImage" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:scaleType="centerCrop" 
       android:fitsSystemWindows="true" 
       android:src="@drawable/bg" 
       app:layout_collapseMode="parallax" /> 

      <android.support.v7.widget.Toolbar 
       android:id="@+id/toolbar" 
       android:layout_width="match_parent" 
       android:layout_height="?attr/actionBarSize" 
       app:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
       app:layout_collapseMode="pin" /> 
     </android.support.design.widget.CollapsingToolbarLayout> 
    </android.support.design.widget.AppBarLayout> 

    <android.support.v4.widget.NestedScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:textSize="28sp" 
      android:lineSpacingExtra="8dp" 
      android:text="@string/long_latin" 
      android:padding="@dimen/activity_horizontal_margin" /> 
    </android.support.v4.widget.NestedScrollView> 

    <android.support.design.widget.FloatingActionButton 
     android:layout_height="wrap_content" 
     android:layout_width="wrap_content" 
     android:layout_margin="@dimen/activity_horizontal_margin" 
     android:src="@drawable/mascot_icon" 
     app:layout_anchor="@id/appBar" 
     app:layout_anchorGravity="bottom|end" /> 
</android.support.design.widget.CoordinatorLayout> 

OUTPUT

enter image description here

+0

ist es gelöst oder nicht? –

Verwandte Themen