片段中的自定义视图与三星设备上的其他片段重叠

时间:2017-03-17 04:23:55

标签: android fragment samsung-mobile custom-view

当我从下面给片段充气时,我面临着重叠片段的问题。

enter image description here 这是布局中的代码:

<FrameLayout
        android:id="@+id/nonAdParent"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/white_blur">

        <FrameLayout
            android:id="@+id/collage_view_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/white_blur"
            android:layout_marginBottom="@dimen/collageview_margin" />

        <FrameLayout
            android:id="@+id/menu_footer"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:background="@color/colorSecondary" />
    </FrameLayout>

片段“collage_view_container”包含1个自定义视图,片段“menu_footer”包含水平Recyclerview。

这是以编程方式编写的代码:

    getSupportFragmentManager().beginTransaction()
            .add(R.id.collage_view_container, new CollageContainerFrag().setLayoutModel(model)).commit();

    FooterMenuFragment footerFrag = new FooterMenuFragment();
    getSupportFragmentManager().beginTransaction()
            .setCustomAnimations(R.anim.slide_in_up, R.anim.no_anim)
            .add(R.id.menu_footer, footerFrag).commit();

问题:“collage_view_container”片段中的自定义视图仅在SAMSUNG设备上的“menu_footer”片段中重叠水平回收视图。 如果我配置此代码:

if (SystemUtils.isSamsungDevice()) {
        getView().setLayerType(View.LAYER_TYPE_SOFTWARE, null); 
}

然后问题没有出现,但应用程序将“缓慢”处理。否则,问题会再次出现。

这是完整的视图代码,其中“nonAdParent”framelayout位于。

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout      
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white_blur"
    android:clipChildren="true"
    android:clipToPadding="false"
    android:fitsSystemWindows="true">

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

    <include layout="@layout/toolbar" />

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ads:adSize="SMART_BANNER"
        ads:adUnitId="ca-app-pub-3940256099942544/6300978111"/> 

    <FrameLayout
        android:id="@+id/adParent"
        android:layout_width="match_parent"
        android:layout_height="20dp"
        android:visibility="gone" />

    <FrameLayout
        android:id="@+id/nonAdParent"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/white_blur">

        <FrameLayout
            android:id="@+id/collage_view_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/white_blur"
            android:layout_marginBottom="@dimen/collageview_margin" />

        <FrameLayout
            android:id="@+id/menu_footer"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:background="@color/colorSecondary" />
    </FrameLayout>

P.S。请告诉我们是否需要更多代码。提前谢谢。

1 个答案:

答案 0 :(得分:0)

使用下面给出的代码替换您的Frame布局(nonAdParent)部分

<RelativeLayout
        android:id="@+id/nonAdParent"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/white_blur">

        <FrameLayout
            android:id="@+id/collage_view_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/white_blur"
            android:layout_alignParentTop="true"
            android:layout_marginBottom="@dimen/collageview_margin" />

        <FrameLayout
            android:id="@+id/menu_footer"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:layout_below="@+id/collage_view_container"
            android:background="@color/colorSecondary" />
    </RelativeLayout>