简体   繁体   English

Android-具有相同底部栏的两个活动

[英]Android - Two activities with the same bottom bar

I have two activities with same bottom bar. 我有两个活动使用相同的底部栏。 The problem is when i call to startActivity from Activity A to Activity B has some blink and is not looking so smooth. 问题是,当我从活动A到活动B调用startActivity时,出现了一些闪烁,并且看起来不太流畅。 for example what I want is like Activity with a container with two fragments and the activity has the bottom bar so this will not change the bottom bar. 例如,我想要的是带有两个片段的容器的活动,而活动具有底部栏,因此这不会更改底部栏。

I know Activity with Fragments can help me with that but is too complicated to change it on my project so is the last option for me. 我知道Activity with Fragments可以帮助我解决这个问题,但是太复杂了,无法在我的项目中更改它,因此对我来说是最后的选择。

I find one more option to do it with SharedElements transition but is supported only from api 21 (Lollipop). 我找到了另一个与SharedElements过渡一起使用的选项,但仅api 21(Lollipop)支持。

在此处输入图片说明

This is my activities and I need the LinearLayout on bottom stay sticky when i change it to Activity B. 这是我的活动,当我将其更改为活动B时,我需要底部的LinearLayout保持粘性。

You can set up activity animations: 您可以设置活动动画:

startActivity();
overridePendingTransition(R.anim.hold, R.anim.fade_in);

Please, refer to this answer: stackoverflow 请参考以下答案: stackoverflow

you can remove the defulat transtion between activites. 您可以删除活动之间的defulat转换。 try this under yourProject/res/values/styles.xml: 在yourProject / res / values / styles.xml下尝试一下:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowAnimationStyle">@null</item>
</style>

If you want the same instance you will have to use fragments. 如果要使用同一实例,则必须使用片段。 If not you could just put that LinearLayout to both layout files. 如果没有,您可以将LinearLayout放到两个布局文件中。 Which one do you want? 你想要哪一个?

You need create a layout and include ex. 您需要创建一个布局并包含ex。 bottombar.xml in layout folder and create the layout. 在布局文件夹中的bottombar.xml并创建布局。

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

if you dont want look delay in change you need use fragments. 如果您不希望外观更改延迟,则需要使用片段。

To manage fragment, i recommended use FragNav 要管理片段,我建议使用FragNav

With this library manage fragments its very easy, remove animation is not solution to your problem 使用此库管理片段非常容易,删除动画并不能解决您的问题

I have made an Activity with two fragments. 我做了一个有两个片段的活动。 In Activity class ,I have write this code for commonBottomSheet :- 在Activity类中,我为commonBottomSheet编写了此代码:

BottomSheetBehavior mBottomSheetBehavior = BottomSheetBehavior.from(findViewById(R.id.bottom_pannel_layout));
mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
mBottomSheetBehavior.setBottomSheetCallback(mBottomSheetCallback);

In Activity xml file in Co-ordinator layout I have included below layout :- 在协调器布局中的Activity xml文件中,我包括以下布局:-

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

In CommonBottomSheetFragment, you can create your layout . 在CommonBottomSheetFragment中,您可以创建您的layout。

And my xml file (bottom_sheet_pannel) for bottomSheet is like this :- 我的bottomSheet的xml文件(bottom_sheet_pannel)就像这样:-

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/bottom_pannel_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    app:behavior_peekHeight="45dp"
    app:layout_behavior="android.support.design.widget.BottomSheetBehavior">

    <ImageView
        android:id="@+id/grabber_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:src="@drawable/ic_vector_slider_grabber"
        android:tint="@color/colorTint" />

    <fragment
        android:id="@+id/rf_common_details_fragment"
        android:layout_marginTop="@dimen/margin_10"
        android:name="com.fragment.CommonBottomSheetFragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
</LinearLayout>

you can change state of bottomSheet with below callBack :- 您可以通过以下callBack更改bottomSheet的状态:-

 private BottomSheetBehavior.BottomSheetCallback mBottomSheetCallback = new BottomSheetBehavior.BottomSheetCallback() {
    @Override
    public void onStateChanged(View bottomSheet, int newState) {
        // do what you want on state change
    }

    @Override
    public void onSlide(View bottomSheet, float slideOffset) {

    }
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM