导航包Navigation最全完整解析(五): 重要接口之BaseLocalPlanner

类似全局路径规划器描述,简化局部路径规划的讨论.

与全局路径规划器想似,在调用局部路径规划时,同样也是在move_base调用nav_core::BaseLocalPlanner接口;

然后用base_local_planner(如DWA)来继承nav_core::BaseLocalPlanner类,并以同样的原理将基类指针指向子类,从而调用子类的函数

  • move_base中调用局部路径规划器的接口
// move_base.cpp(节选)

boost::shared_ptr<nav_core::BaseLocalPlanner> tc_;

//@ian 初始化局部路径规划器.
    if(config.base_local_planner != last_config_.base_local_planner<
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
好的,以下是一个简单的 Android 应用程序,其中括一个底部导航栏(BottomNavigationView)。 首先,我们需要在 `build.gradle` 文件中添加 `implementation 'com.google.android.material:material:1.2.1'`,这将为我们提供 Material Design 库,其中括 BottomNavigationView。 接下来,我们需要在 `activity_main.xml` 文件中添加一个 BottomNavigationView: ```xml <com.google.android.material.bottomnavigation.BottomNavigationView android:id="@+id/bottom_navigation" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" app:menu="@menu/bottom_navigation_menu" /> ``` `menu` 属性是一个指向我们的菜单资源文件的引用,我们需要在 `res` 文件夹下创建一个名为 `menu` 的文件夹,并在其中创建一个名为 `bottom_navigation_menu.xml` 的文件,它应该如下所示: ```xml <menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/navigation_home" android:icon="@drawable/ic_home" android:title="@string/title_home" /> <item android:id="@+id/navigation_dashboard" android:icon="@drawable/ic_dashboard" android:title="@string/title_dashboard" /> <item android:id="@+id/navigation_notifications" android:icon="@drawable/ic_notifications" android:title="@string/title_notifications" /> </menu> ``` 现在,我们需要在我们的 `MainActivity` 中使用 BottomNavigationView。以下是 MainActivity 的完整代码: ```java public class MainActivity extends AppCompatActivity { private BottomNavigationView bottomNavigationView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); bottomNavigationView = findViewById(R.id.bottom_navigation); bottomNavigationView.setOnNavigationItemSelectedListener(navListener); getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new HomeFragment()).commit(); } private BottomNavigationView.OnNavigationItemSelectedListener navListener = new BottomNavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(@NonNull MenuItem item) { Fragment selectedFragment = null; switch (item.getItemId()) { case R.id.navigation_home: selectedFragment = new HomeFragment(); break; case R.id.navigation_dashboard: selectedFragment = new DashboardFragment(); break; case R.id.navigation_notifications: selectedFragment = new NotificationsFragment(); break; } getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, selectedFragment).commit(); return true; } }; } ``` 我们在 `onCreate` 方法中获取 BottomNavigationView,并为其设置一个 `OnNavigationItemSelectedListener`,以便在用户选择某个导航项时切换 Fragment。我们还在 `onCreate` 方法中添加了一个名为 `HomeFragment` 的 Fragment,这是我们默认显示的 Fragment。 现在,我们需要为每个导航项创建一个 Fragment。以下是我们的三个 Fragment: ```java public class HomeFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment return inflater.inflate(R.layout.fragment_home, container, false); } } public class DashboardFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment return inflater.inflate(R.layout.fragment_dashboard, container, false); } } public class NotificationsFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment return inflater.inflate(R.layout.fragment_notifications, container, false); } } ``` 最后,我们需要创建我们的三个 Fragment 布局文件。这些布局文件可以含任何你想要的内容,我将使用一个简单的 TextView 演示: ```xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/text_view" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="Home Fragment" /> </RelativeLayout> ``` ```xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/text_view" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="Dashboard Fragment" /> </RelativeLayout> ``` ```xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/text_view" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="Notifications Fragment" /> </RelativeLayout> ``` 这样,我们就完成了一个简单的 Android 应用程序,其中括一个底部导航栏。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

爱发呆de白菜头

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值