旋转后滚动Android Fragment

时间:2016-05-03 11:26:43

标签: android fragment android-orientation

我在Android应用程序的开发过程中遇到了一个问题。这是我在纵向模式下的应用程序:

enter image description here

但是当我改变旋转时,主转换器表面会滚动出屏幕。这是旋转后的相同屏幕: enter image description here

这是我的项目repo的链接。非常感谢任何帮助。

fragment_main:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
tools:context="org.ogasimli.manat.activity.MainActivity">

<android.support.design.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:background="?colorPrimary"
        app:elevation="@dimen/app_bar_elevation"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar_main"
            android:layout_width="match_parent"
            android:layout_height="?actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/AppTheme.AppBarOverlay">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="?actionBarSize"
                android:layout_gravity="center_horizontal"
                android:contentDescription="@string/app_name"
                android:scaleType="center"
                android:src="@drawable/ic_app_name"/>

        </android.support.v7.widget.Toolbar>

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

    <LinearLayout
        android:id="@+id/main_result_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:visibility="visible"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <include
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            layout="@layout/converter_surface"
            android:layout_gravity="center_horizontal"/>

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerview_main"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layoutManager="LinearLayoutManager"
            tools:listitem="@layout/main_currency_item"/>

    </LinearLayout>

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

<LinearLayout
    android:id="@+id/main_error_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:layout_centerInParent="true"
    android:orientation="vertical"
    android:visibility="gone">

    <include
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        layout="@layout/main_error_view"
        android:layout_gravity="center"/>

</LinearLayout>

<com.google.android.gms.ads.AdView
    android:id="@+id/adView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    ads:adSize="BANNER"
    ads:adUnitId="@string/banner_ad_unit_id"
    android:layout_centerHorizontal="true"
    android:layout_alignParentBottom="true"/>

<FrameLayout
    android:id="@+id/snackBar_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_margin="@dimen/activity_horizontal_margin"/>

</RelativeLayout>
横向模式中的

fragment_main:

<?xml version="1.0" encoding="utf-8"?>
<!--  TODO: fix issue with  hiding of converter on rotation -->
<RelativeLayout
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="org.ogasimli.manat.activity.MainActivity">

<android.support.design.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:background="?colorPrimary"
        app:elevation="@dimen/app_bar_elevation"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar_main"
            android:layout_width="match_parent"
            android:layout_height="?actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/AppTheme.AppBarOverlay">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="?actionBarSize"
                android:layout_gravity="center_horizontal"
                android:contentDescription="@string/app_name"
                android:scaleType="center"
                android:src="@drawable/ic_app_name"/>

        </android.support.v7.widget.Toolbar>

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

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <android.support.v4.widget.NestedScrollView
            android:layout_width="@dimen/main_fragment_width"
            android:layout_height="match_parent"
            android:layout_centerHorizontal="true">

            <LinearLayout
                android:id="@+id/main_result_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:visibility="visible">

                <include
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    layout="@layout/converter_surface"/>

                <android.support.v7.widget.RecyclerView
                    android:id="@+id/recyclerview_main"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    app:layoutManager="LinearLayoutManager"
                    tools:listitem="@layout/main_currency_item"
                    android:elevation="@dimen/converter_elevation"
                    tools:targetApi="lollipop"/>

            </LinearLayout>

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

    </RelativeLayout>

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

<LinearLayout
    android:id="@+id/main_error_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:layout_centerInParent="true"
    android:orientation="vertical"
    android:visibility="gone">

    <include
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        layout="@layout/main_error_view"
        android:layout_gravity="center"/>

</LinearLayout>

<FrameLayout
    android:id="@+id/snackBar_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_margin="@dimen/activity_horizontal_margin"/>

</RelativeLayout>

0 个答案:

没有答案