2017-07-06 4 views
0

Wenn ich zum Ende meiner NestedScrollView blättern und das Gerät rotiere, wird meine Position in der Liste gespeichert, aber wenn ich zurück in den Hochformatmodus blicke, wird die ImageView im AppBarLayout erweitert, anstatt wie ursprünglich gedreht. Ich möchte zu dem vor der Rotation zurückkehren, wobei das Bild entweder teilweise kollabiert oder vollständig kollabiert ist.Wie stelle ich meine Position in einem CoordinatorLayout nach der Rotation wieder her?


Vor Gerätedrehung

[1]


Nach Gerätedrehung

[2]

XML-Datei:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/coordinator_layout" 
    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:id="@+id/app_bar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 

     <android.support.design.widget.CollapsingToolbarLayout 
      android:id="@+id/collapsing_toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      app:layout_scrollFlags="scroll|exitUntilCollapsed"> 

      <ImageView 
       android:id="@+id/album_art" 
       android:layout_width="match_parent" 
       android:layout_height="300dp" 
       android:scaleType="fitXY" 
       app:layout_collapseMode="parallax" 
       app:layout_collapseParallaxMultiplier="0.7" 
       android:src="@drawable/the_getaway_album" 
       android:contentDescription="@string/album_art_description" /> 

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

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

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

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical"> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="vertical" 
       android:padding="@dimen/standard_padding" > 

       <TextView 
        android:id="@+id/album_title" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:maxLines="3" 
        android:textSize="@dimen/large_text_size" 
        android:textStyle="bold" /> 

       <TextView 
        android:id="@+id/explicitness" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginBottom="@dimen/standard_padding" 
        android:background="@drawable/rounded_border_filled" 
        android:text="@string/explicit_tag" 
        android:textAlignment="center" 
        android:textColor="@android:color/white" 
        android:textSize="@dimen/standard_text_size" 
        android:textStyle="bold" 
        android:visibility="invisible"/> 

       <TextView 
        android:id="@+id/artist" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"/> 

       <TextView 
        android:id="@+id/release_date" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" /> 

      </LinearLayout> 

      <TextView 
       android:id="@+id/album_price" 
       android:layout_width="@dimen/large_price_bubble_length" 
       android:layout_height="wrap_content" 
       android:layout_marginBottom="@dimen/activity_vertical_margin" 
       android:layout_gravity="center_horizontal" 
       android:background="@drawable/rounded_border" 
       android:textAlignment="center" 
       android:textColor="@color/colorAccent" 
       android:textSize="@dimen/standard_text_size"/> 

      <TextView 
       android:id="@+id/copyright" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center" 
       android:maxLines="2" 
       android:ellipsize="end" 
       android:textSize="12sp" 
       android:textColor="@android:color/secondary_text_dark" 
       android:textAlignment="center"/> 

      <View 
       android:layout_width="match_parent" 
       android:layout_height="1dp" 
       android:layout_margin="@dimen/activity_horizontal_margin" 
       android:background="@android:color/darker_gray"/> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="@string/track_list_title" 
       android:textSize="@dimen/standard_text_size" 
       android:textStyle="bold" 
       android:textAlignment="center"/> 

      <LinearLayout 
       android:id="@+id/track_list" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="vertical"> 
      </LinearLayout> 

     </LinearLayout> 

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

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

Antwort

-1

configChanges param Datei hinzufügen zu manifestieren es für mich gearbeitet,

<activity 
      android:name=".MainActivity" 
      android:configChanges="orientation|screenSize"/> 
+0

Das ist nicht –

+0

In Eibisch funktioniert hat seine Arbeit gut, die Einrichtung Ihren Tests –

Verwandte Themen