当我滚动到NestedScrollView的底部并旋转设备时,我的列表中的位置被保存,但是当我旋转回纵向模式时,AppBarLayout中的ImageView会像我最初旋转屏幕时那样展开而不是折叠。我想回到旋转之前的状态,图像部分折叠或完全折叠。
设备轮换之前
设备轮换后
XML文件:
<?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>
答案 0 :(得分:-1)
将configChanges param添加到它为我工作的清单文件中,
<activity
android:name=".MainActivity"
android:configChanges="orientation|screenSize"/>