Android 项目必备(十二)--> APP 底部导航栏最佳实践

2023-11-05

在这里插入图片描述

简介

当开始一个新项目的时候,有一个很重要的步骤就是确定我们的 APP 首页框架,也就是用户从桌面点击 APP 图标,进入 APP 首页的时候展示给用户的框架,比如微信,展示了有四个 Tab ,分别对应不同的板块(微信、通讯录、发现、我),现在市面出了少部分的 Material Design 风格的除外,大部分都是这样的一个框架,称之为底部导航栏。
在这里插入图片描述

TabLayout + Fragment

1. 效果图

在这里插入图片描述

2. 布局文件
<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".TabLayoutActivity">

    <FrameLayout
        android:id="@+id/home_container"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />

    <View android:layout_width="match_parent"
        android:layout_height="0.5dp"
        android:alpha="0.6"
        android:background="@android:color/darker_gray"/>

    <com.google.android.material.tabs.TabLayout
        android:id="@+id/bottom_tab_layout"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        app:tabIndicatorHeight="0dp"
        app:tabSelectedTextColor="@android:color/black"
        app:tabTextColor="@android:color/darker_gray"/>


</LinearLayout>
3. 代码
public class TabLayoutActivity extends AppCompatActivity {
    @BindView(R.id.bottom_tab_layout)
    TabLayout mTabLayout;

    private Fragment[]mFragmensts;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tab_layout);
        ButterKnife.bind(this);
        mFragmensts = DataGenerator.getFragments("TabLayout Tab");

        initView();
    }

    private void initView() {
        mTabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                onTabItemSelected(tab.getPosition());

                for (int i=0;i<mTabLayout.getTabCount();i++){
                    View view = mTabLayout.getTabAt(i).getCustomView();
                    ImageView icon = (ImageView) view.findViewById(R.id.tab_content_image);
                    TextView text = (TextView) view.findViewById(R.id.tab_content_text);
                    if(i == tab.getPosition()){
                        icon.setImageResource(DataGenerator.mTabResPressed[i]);
                        text.setTextColor(getResources().getColor(android.R.color.black));
                    }else{
                        icon.setImageResource(DataGenerator.mTabRes[i]);
                        text.setTextColor(getResources().getColor(android.R.color.darker_gray));
                    }
                }


            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });

        for(int i=0;i<4;i++){
            mTabLayout.addTab(mTabLayout.newTab().setCustomView(DataGenerator.getTabView(this,i)));
        }
    }

    private void onTabItemSelected(int position){
        Fragment fragment = null;
        switch (position){
            case 0:
                fragment = mFragmensts[0];
                break;
            case 1:
                fragment = mFragmensts[1];
                break;

            case 2:
                fragment = mFragmensts[2];
                break;
            case 3:
                fragment = mFragmensts[3];
                break;
        }
        if(fragment!=null) {
            getSupportFragmentManager().beginTransaction().replace(R.id.home_container,fragment).commit();
        }
    }
}

推荐阅读 【Kevin Learn Android】–>TabLayout

BottomNavigationView + Fragment

1. 效果图

在这里插入图片描述

2. 布局文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <FrameLayout
        android:id="@+id/fl_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@id/bottomNavigationView" />

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottomNavigationView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/white"
        android:layout_alignParentBottom="true"
        app:itemTextColor="@drawable/bottom_navigation_item_selector"
        app:menu="@menu/main_bottom_navigation" />

</RelativeLayout>
3. main_bottom_navigation.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <item
        android:id="@+id/menu_message"
        android:enabled="true"
        android:icon="@drawable/sel_home"
        android:title="首页"
        app:showAsAction="ifRoom" />
    <item
        android:id="@+id/menu_contacts"
        android:enabled="true"
        android:icon="@drawable/sel_mine"
        android:title="我的"
        app:showAsAction="ifRoom" />
</menu>
4. 代码
public class MainActivity extends BaseActivity {
    private HomeFragment mHomeFragment = HomeFragmentFactory.getInstance().getHomeFragment();
    private MineFragment mMineFragment = HomeFragmentFactory.getInstance().getMineFragment();

    private List<Fragment> mFragments = new ArrayList<>();

    @BindView(R.id.bottomNavigationView)
    BottomNavigationView mNavigationView;

    @Override
    public int getLayoutId() {
        return R.layout.activity_main;
    }

    @Override
    public void initView() {
        mFragments.add(mHomeFragment);
        mFragments.add(mMineFragment);

        mNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                switchFragment(item.getItemId());
                return true;
            }
        });

        switchFragment(R.id.menu_message);
    }

    /**
     * 切换fragment
     *
     * @param id
     * @return
     */
    private void switchFragment(int id) {
        Fragment fragment = null;
        switch (id) {
            case R.id.menu_message:
                fragment = mFragments.get(0);
                break;

            case R.id.menu_contacts:
                fragment = mFragments.get(1);
                break;

            default:
                break;
        }
        if (fragment != null) {
            getSupportFragmentManager().beginTransaction().replace(R.id.fl_content,fragment).commit();
        }
    }


}

推荐阅读:【Kevin Learn Android】–>BottomNavigationView

RadioGroup + ViewPager2 + Fragment

1. 效果图
在这里插入图片描述
2. 布局文件
style.xml

	<style name="Custom" />

    <style name="Custom.TabRadioButton">
        <item name="android:layout_width">0dp</item>
        <item name="android:layout_weight">1</item>
        <item name="android:layout_height">match_parent</item>
        <item name="android:padding">5dp</item>
        <item name="android:gravity">center</item>
        <item name="android:button">@null</item>
        <item name="android:textSize">14sp</item>
        <item name="android:textColor">@color/black</item>
    </style>
<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".TabLayoutActivity">

    <androidx.viewpager2.widget.ViewPager2
        android:id="@+id/vp_container"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />

    <View android:layout_width="match_parent"
        android:layout_height="0.5dp"
        android:alpha="0.6"
        android:background="@android:color/darker_gray"/>

    <RadioGroup
        android:id="@+id/rg_tabs"
        android:layout_width="match_parent"
        android:layout_height="56dp"
        android:background="#dcdcdc"
        android:orientation="horizontal">

        <RadioButton
            android:id="@+id/tab_home"
            style="@style/Custom.TabRadioButton"
            android:checked="true"
            android:drawableTop="@drawable/tab_home_selector"
            android:text="首页" />

        <RadioButton
            android:id="@+id/tab_discover"
            style="@style/Custom.TabRadioButton"
            android:drawableTop="@drawable/tab_discovery_selector"
            android:text="发现" />

        <RadioButton
            android:id="@+id/tab_attention"
            style="@style/Custom.TabRadioButton"
            android:drawableTop="@drawable/tab_attention_selector"
            android:text="关注" />

        <RadioButton
            android:id="@+id/tab_profile"
            style="@style/Custom.TabRadioButton"
            android:drawableTop="@drawable/tab_profile_selector"
            android:text="我的" />

    </RadioGroup>
</LinearLayout>

3. MyPagerAdapter.java

public class MyPagerAdapter extends FragmentStateAdapter {
    private List<Class> fragments;

    public MyPagerAdapter(FragmentActivity fragmentActivity) {
        super(fragmentActivity);
        if (fragments == null) {
            fragments = new ArrayList<>();
        }
    }

    public void addFragment(Fragment fragment) {
        if (fragments != null) {
            fragments.add(fragment.getClass());
        }
    }

    @NonNull
    @Override
    public Fragment createFragment(int position) {
        try {
            return (Fragment) fragments.get(position).newInstance();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public int getItemCount() {
        return fragments == null ? 0 : fragments.size();
    }
}

4. TabLayoutActivity.java

public class TabLayoutActivity extends AppCompatActivity {
    @BindView(R.id.rg_tabs)
    RadioGroup mRadioGroup;

    @BindView(R.id.vp_container)
    ViewPager2 mViewPager2;

    @BindView(R.id.tab_home)
    RadioButton mRadioHome;

    @BindView(R.id.tab_discover)
    RadioButton mRadioDiscover;

    @BindView(R.id.tab_attention)
    RadioButton mRadioAttention;

    @BindView(R.id.tab_profile)
    RadioButton mRadioProfile;

    private MyPagerAdapter mAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tab_layout);
        ButterKnife.bind(this);
        initView();
    }

    private void initView() {
        mViewPager2.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
            @Override
            public void onPageSelected(int position) {
                super.onPageSelected(position);
                switch (position) {
                    case 0:
                        mRadioHome.setChecked(true);
                        break;

                    case 1:
                        mRadioDiscover.setChecked(true);
                        break;

                    case 2:
                        mRadioAttention.setChecked(true);
                        break;

                    case 3:
                        mRadioProfile.setChecked(true);
                        break;

                    default:
                        break;
                }
            }
        });

        mRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int checkId) {
                switch (checkId) {
                    case R.id.tab_home:
                        mViewPager2.setCurrentItem(0);
                        break;

                    case R.id.tab_discover:
                        mViewPager2.setCurrentItem(1);
                        break;

                    case R.id.tab_attention:
                        mViewPager2.setCurrentItem(2);
                        break;

                    case R.id.tab_profile:
                        mViewPager2.setCurrentItem(3);
                        break;

                    default:
                        break;
                }
            }
        });
        mAdapter = new MyPagerAdapter(this);
        mViewPager2.setAdapter(mAdapter);
        mAdapter.addFragment(new HomeFragment());
        mAdapter.addFragment(new DiscoveryFragment());
        mAdapter.addFragment(new AttentionFragment());
        mAdapter.addFragment(new ProfileFragment());
        mViewPager2.setCurrentItem(0);
    }
}

带页面跳转功能的底部导航

1. 效果图
在这里插入图片描述

2. 布局文件

<?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".TabLayoutActivity">

    <FrameLayout
        android:id="@+id/fragment_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/rg_tabs" />

    <RadioGroup
        android:id="@+id/rg_tabs"
        android:layout_width="match_parent"
        android:layout_height="56dp"
        android:background="#dcdcdc"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal">

        <RadioButton
            android:id="@+id/tab_home"
            style="@style/Custom.TabRadioButton"
            android:checked="true"
            android:drawableTop="@drawable/tab_home_selector"
            android:text="首页" />

        <RadioButton
            android:id="@+id/tab_discover"
            style="@style/Custom.TabRadioButton"
            android:drawableTop="@drawable/tab_discovery_selector"
            android:text="发现" />

        <View style="@style/Custom.TabRadioButton" />

        <RadioButton
            android:id="@+id/tab_attention"
            style="@style/Custom.TabRadioButton"
            android:drawableTop="@drawable/tab_attention_selector"
            android:text="关注" />

        <RadioButton
            android:id="@+id/tab_profile"
            style="@style/Custom.TabRadioButton"
            android:drawableTop="@drawable/tab_profile_selector"
            android:text="我的" />

    </RadioGroup>

    <ImageView
        android:id="@+id/sign_iv"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:background="@android:color/transparent"
        android:src="@mipmap/ic_add" />
</RelativeLayout>

3. 代码

public class TabLayoutActivity extends AppCompatActivity {
    @BindView(R.id.rg_tabs)
    RadioGroup mRadioGroup;

    @BindView(R.id.tab_home)
    RadioButton mRadioHome;

    @BindView(R.id.tab_discover)
    RadioButton mRadioDiscover;

    @BindView(R.id.tab_attention)
    RadioButton mRadioAttention;

    @BindView(R.id.tab_profile)
    RadioButton mRadioProfile;

    private List<Fragment> mFragmensts;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tab_layout);
        ButterKnife.bind(this);
        mFragmensts = DataGenerator.getFragments("TabLayout Tab");
        initView();
    }

    private void initView() {
        onTabItemSelected(0);
        mRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int checkId) {
                switch (checkId) {
                    case R.id.tab_home:
                        onTabItemSelected(0);
                        break;

                    case R.id.tab_discover:
                        onTabItemSelected(1);
                        break;

                    case R.id.tab_attention:
                        onTabItemSelected(2);
                        break;

                    case R.id.tab_profile:
                        onTabItemSelected(3);
                        break;

                    default:
                        break;
                }
            }
        });
    }

    private void onTabItemSelected(int position){
        Fragment fragment = null;
        switch (position){
            case 0:
                fragment = mFragmensts.get(0);
                break;
            case 1:
                fragment = mFragmensts.get(1);
                break;

            case 2:
                fragment = mFragmensts.get(2);
                break;
            case 3:
                fragment = mFragmensts.get(3);
                break;
        }
        if(fragment!=null) {
            getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,fragment).commit();
        }
    }


}

PagerBottomTabStrip

BottomNavigation + Fragment

1. 效果图
效果图

2. 在 app/build.gradle 中添加:
implementation 'com.ashokvarma.android:bottom-navigation-bar:2.1.0'

3. 布局文件

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:orientation="vertical"
    tools:context=".ui.BottomNavigationActivity">

    <include
        android:id="@+id/include4"
        layout="@layout/layout_toolbar"/>

    <FrameLayout
        android:id="@+id/fl_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_constraintBottom_toTopOf="@+id/bottom_navigation_bar"
        app:layout_constraintTop_toBottomOf="@+id/include4" />

    <com.ashokvarma.bottomnavigation.BottomNavigationBar
        android:id="@+id/bottom_navigation_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

4. 代码

public class BottomNavigationActivity extends BaseActivity implements BottomNavigationBar.OnTabSelectedListener {
    @BindView(R.id.bottom_navigation_bar)
    BottomNavigationBar mNavigationBar;

    private InviteFragment mInviteFragment = HomeFragmentFactory.getInstance().getInviteFragment();
    private ActivityFragment mActivityFragment = HomeFragmentFactory.getInstance().getActivityFragment();
    private FoundFragment mFoundFragment = HomeFragmentFactory.getInstance().getFoundFragment();
    private MineFragment mMineFragment = HomeFragmentFactory.getInstance().getMineFragment();

    private Fragment currentFragment = new Fragment();
//    private TextBadgeItem mBadgeItem;
    private FragmentManager fm;


    @Override
    protected int getLayoutId() {
        return R.layout.activity_bottom_navigation;
    }

    @Override
    protected void setToolbar() {

    }

    @Override
    protected void initView() {
        setNavTitle(R.string.bottom_navigation);

        fm = getSupportFragmentManager();

        initBottomBar();

    }

    private void initBottomBar() {

        /**
         * 导航基础设置 包括按钮选中效果 导航栏背景色等
         */
        mNavigationBar.setTabSelectedListener(this)
                .setMode(BottomNavigationBar.MODE_FIXED)
                .setBackgroundStyle(BottomNavigationBar.BACKGROUND_STYLE_STATIC)
                .setActiveColor("#F5DF3E")//选中颜色
                .setInActiveColor("#000000")//未选中颜色
                .setBarBackgroundColor("#ffffff");//导航栏背景色
//        mBadgeItem = new TextBadgeItem()
//                .setBorderWidth(2)//Badge的Border(边界)宽度
//                .setBorderColor(Color.BLUE)//Badge的Border颜色
//                .setBackgroundColor(Color.RED)
//                .setTextColor(Color.BLACK)//文本颜色
//                .setGravity(Gravity.RIGHT| Gravity.TOP)//位置,默认右上角
//                .setAnimationDuration(2000)
//                .setHideOnSelect(true)//当选中状态时消失,非选中状态显示
//                .setText("9");

        setInvite();


    }

    /**
     * 切换fragment
     *
     * @param targetFragment
     * @return
     */
    private FragmentTransaction switchFragment(Fragment targetFragment) {
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        if (!targetFragment.isAdded()) {
            // 第一次使用switchFragment()时currentFragment为null,所以要判断一下
            if (currentFragment != null) {
                transaction.hide(currentFragment);
            }
            transaction.add(R.id.fl_content, targetFragment, targetFragment.getClass().getName());
        } else {
            transaction.hide(currentFragment).show(targetFragment);
        }
        currentFragment = targetFragment;
        return transaction;
    }


    /**
     * 邀请
     */
    private void setInvite() {
        mNavigationBar.clearAll();
        switchFragment(mInviteFragment).commitNowAllowingStateLoss();
        mNavigationBar.addItem(new BottomNavigationItem(R.mipmap.icon_invite_nor,"邀约"))
                .addItem(new BottomNavigationItem(R.mipmap.icon_activity_nor,"活动"))
                .addItem(new BottomNavigationItem(R.mipmap.icon_find_nor,"发现"))
                .addItem(new BottomNavigationItem(R.mipmap.icon_my_nor,"我的"))
                .setFirstSelectedPosition(0)
                .initialise();

    }

    /**
     * 活动
     */
    private void setActivity() {
        mNavigationBar.clearAll();
        switchFragment(mActivityFragment).commitNowAllowingStateLoss();
        mNavigationBar.addItem(new BottomNavigationItem(R.mipmap.icon_invite_nor,"邀约"))
                .addItem(new BottomNavigationItem(R.mipmap.icon_activity_nor,"活动"))
                .addItem(new BottomNavigationItem(R.mipmap.icon_find_nor,"发现"))
                .addItem(new BottomNavigationItem(R.mipmap.icon_my_nor,"我的"))
                .setFirstSelectedPosition(1)
                .initialise();

    }

    /**
     * 发现
     */
    private void setFound() {
        mNavigationBar.clearAll();
        switchFragment(mFoundFragment).commitNowAllowingStateLoss();
        mNavigationBar.addItem(new BottomNavigationItem(R.mipmap.icon_invite_nor,"邀约"))
                .addItem(new BottomNavigationItem(R.mipmap.icon_activity_nor,"活动"))
                .addItem(new BottomNavigationItem(R.mipmap.icon_find_nor,"发现"))
                .addItem(new BottomNavigationItem(R.mipmap.icon_my_nor,"我的"))
                .setFirstSelectedPosition(2)
                .initialise();

    }

    /**
     * 我的
     */
    private void setMine() {
        mNavigationBar.clearAll();
        switchFragment(mMineFragment).commitNowAllowingStateLoss();
        mNavigationBar.addItem(new BottomNavigationItem(R.mipmap.icon_invite_nor,"邀约"))
                .addItem(new BottomNavigationItem(R.mipmap.icon_activity_nor,"活动"))
                .addItem(new BottomNavigationItem(R.mipmap.icon_find_nor,"发现"))
                .addItem(new BottomNavigationItem(R.mipmap.icon_my_nor,"我的"))
                .setFirstSelectedPosition(3)
                .initialise();

    }

    @Override
    public void onTabSelected(int position) {
        FragmentTransaction ft = fm.beginTransaction();
        switch (position) {
            case 0:
                setInvite();
                break;

            case 1:
                setActivity();
                break;

            case 2:
                setFound();
                break;

            case 3:
                setMine();
                break;
        }

    }

    @Override
    public void onTabUnselected(int position) {

    }

    @Override
    public void onTabReselected(int position) {

    }
}

推荐阅读:【第三方开源库】–> BottomNavigation 底部导航栏

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Android 项目必备(十二)--> APP 底部导航栏最佳实践 的相关文章

  • 史上最全的2023年最新版Android面试题集锦(含答案解析)

    前言 又到了一年的金三银四黄金求职季 虽说今年以来 经济回暖 但行业岗位缺口紧缩的趋势恢复还需一段时间 尤其对于Android开发而言 想要跳槽到一个高薪岗位更是难上加难 因此 想要杀出重围 必然要有万全的准备 除了一份美观的简历 还必须刷
  • Android无线网络调试手机

    adb tcpip 5555 adb下载地址 http download clockworkmod com test UniversalAdbDriverSetup msi 3 在设备中下载超级终端 是andriod软件 设置端口 su s
  • BAT Android面试专题深入探究:四大组件+ViewPager+组件化架构+Bitmap

    本篇是结合我之前面试别人的经验 以及跟一些在BAT上班的朋友 讨论总结出的一份很深的大公司需要用到的一些高端Android技术 这里也专门整理了一个文档 重点和难点都有详细解析 这些题目有点技术含量 需要好点时间去研究一下的 在文末有领取
  • c++ java rgb与nv21互转

    目录 jni函数 c rgb转nv21 可以转 不报错 但是转完只有黑白图 java yuv420保存图片 先转nv21 再保存ok c yuv420月bgr互转 测试ok jni函数 JNIEXPORT void JNICALL Java
  • Android开发学习【Button控件】

    Android开发学习 Day02 Button 与TextView相比 Button增加了两个新属性 书写一个点击显示当前时间的按钮 获取当前时间的java类 xml主界面 MainActivity类 点击事件和长按事件 使用setOnC
  • 在 Android Studio 2.2 中愉快地使用 C/C++

    使用 Android studio 你可以将 C 和 C 代码编译成 native library 然后打包到你的 APK 中 你的 Java 代码可以通过 Java Native Interface JNI 调用 native libra
  • Compose 动画边学边做 - 夏日彩虹

    引言 Compose 在动画方面下足了功夫 提供了种类丰富的 API 但也正由于 API 种类繁多 如果想一气儿学下来 可能会消化不良导致似懂非懂 结合例子学习是一个不错的方法 本文就带大家边学边做 通过高仿微博长按点赞的彩虹动画 学习和实
  • Android Studio Debug:编码五分钟,调试俩小时

    前言 整理并积累Android开发过程中用到的一些调试技巧 通过技巧性的调试技能 辅助增强代码的健壮性 安全性 正确性 案例一 抛出明显异常 常见的 除数为0问题 class MainActivty AppCompatActivity ov
  • Android 宽高相等的adapter item内容

    使用一张网上的图 很多时候 我们需要用使用这样的排列 宽高固定 然后是中间留有一定的边距 毫无疑问 这里我们需要用到gridadapter GridView的item是正方形 而android需要适配不同尺寸的手机 所以不能写死item的高
  • ubuntu18.04的Android环境配置

    文章目录 1 安装Java jdk 2 安装Android studio 3 安装android sdk 4 安装 ndk 5 添加环境变量 1 安装Java jdk sudo apt get install openjdk 8 jre o
  • Flutter 完整示例

    经过这一段对 Flutter 的了解和接触 掌握如何完整使用 Flutter 开发一个项目 实际上 在 Flutter 中 一切皆 widget 我们的界面都是由各种 widget 堆叠出来的 一个 Flutter 工程涉及以下几个要点 工
  • 申请Google Player帐号上传自己开发的App

    1 访问https play google com apps publish signup 2 输入个人信息 3 在选择国家 地区时 由于列表中没有中国 所以我们只能选择香港 注册Google Player开发帐号是需要支付25美元费用的
  • Android应用程序如何访问/sys和/proc等目录下的系统文件

    Android 下应用程序不能直接 获得 root 权限 因此如果需要修改 sys 或 proc 等目录下的文件时 有以下两种方法可以选择 通过 service 或虚拟设备的方法将使得应用程序临时 获得 root 权限 对 sys 或 pr
  • Android用surface直接显示yuv数据(二)

    研究了一段时间Android的surface系统 一直执着地认为所有在surface或者屏幕上显示的画面 必须要转换成RGB才能显示 yuv数据也要通过颜色空间转换成RGB才能显示 可最近在研究stagefright视频显示时发现 根本找不
  • 【Android开发】一文全面解析Framework层

    前言 上一篇文章从Native角度讲解了Android进程管理的相关概念 本文将继续从上层的Framework中的进程启动 销毁场景和优先级处理 以及它们与四大组件的种种关联 来逐步解析Android进程管理的其他关键要素 进程的启动 An
  • Android studio创建秘钥提示JKS密钥库使用专用格式。建议使用“keytool -importkeystore -srckeystore....

    1 复制图中 内的内容 keytool importkeystore srckeystore F AndroidTestKey testtow jks destkeystore F AndroidTestKey testtow jks de
  • 小米手机无法调试应用解决Installation failed with message Failed to establish session.

    小米手机性价比高 有些问题也很尖锐 比如我的5S用了黑科技 试验品 超声波指纹解锁 识别率就很低 每次解锁都要哈口气 真后悔 而且最近又遇到新问题 我的小米5S无法通过android studio调试应用 卖批啊 但即使这样也比蓝绿工程的O
  • 安卓MediaRecorder(2)录制源码分析

    文章目录 前言 JAVA new MediaRecorder 源码分析 android media MediaRecorder cpp native init MediaRecorder java postEventFromNative a
  • Android的基础开发

    基础开发 listView ListView就是列表条目 可以向下滚动 也可以点击 首先设置两个视图布局 activity main2 xml 充当容器 ListView
  • Android的组件、布局学习

    介绍 公司组织架构调整 项目组需要承接其他项目组的android项目 负责维护和开发新需求 故学习下基础语法和项目开发 组件学习 Toolbar header布局部分 就是app最顶部的部分 他的显示与否 是与F androidProjec

随机推荐

  • python pip在哪个文件夹运行_python pip源配置,pip配置文件存放位置的方法

    pip源配置文件可以放置的位置 Linux Unix etc pip con pip pip conf 每一个我都找了都没有 所以我是在这个文件夹中创建的pip conf文件 config pip pip conf Mac OSX Libr
  • java自定义findbugs规则_findbugs自定义规则并配置实现检测

    findbugs不过多介绍了 对于这个主题找了一些资料 没有找到一个完整的介绍 要么是介绍怎么写detector 要么就是没有完整的介绍怎么配置生效 下面主要介绍一下怎么配置其生效 至于怎么写这个detector还是有很多资料说明的 不过在
  • 51单片机I/O口灌电流、拉电流、上拉电阻的联系

    一 灌电流 拉电流 我们可以通过编写程序直接控制单片机的I O口的电平是高还是低 但是却控制不了电流的大小 而电流又涉及到了驱动能力的问题 也就是说能不能带动你所加的负载 1 1什么是灌电流 拉电流 如图1 单片机 p1 0口 输出低电平时
  • Wireless Password 【HDU - 2825】【AC自动机+状压DP】

    题目链接 好题一道 推了一会 然后计算了一下时间复杂度 差不多最坏情况是25 100 1024 26 66560000然后看了下 嗯 能搞 有搞头哈哈哈 然后写了一下 首先 WA了 发现竟然是最大极限哪儿写错了 我的个天呐 A 我们看到最多
  • Hibernate 一对一关系(基于XML)

    场景 当一个实体跟另一个实体存在一对一关系时 就可以用hibernate的one to one mapping来处理啦 本教程将会讲解如何用hibernate来解决两个存在1对1关联关系的表之间的级联save问题 本教程用到的开发工具和技术
  • 2022年全网首发

    整篇文章约2 5万字 不包含引用和连接内容 回顾过去 2019 2020年 2021年 本文的行文思路 第一部分 学习路径概览 编程语言 Linux基础 数据库入门 计算机基础 Java基础 分布式理论篇 网络通信篇 离线计算篇 消息队列篇
  • Word2Vec和Doc2Vec模型

    NLP初级教程 刘建平博客 word2vec参数调整 及lda调参 Word2vec和Doc2vec原理理解并结合代码分析 基于gensim的Doc2Vec Word2Vec Word2Vec是Google在2013年开源的一款将词表征为实
  • Idea快捷键大全(Windows)

    一 知道类名查找类 1 Ctrl Shift Alt N 2 双击Shift 二 查找类中所有方法 Ctrl F12 三 快速查找类或方法在整个项目中的位置 按住Ctrl键再点击类或方法会出现所有用到过的文件对象
  • Map集合案例-统计投票人数

    需求 某个班级80名学生 现在需要组成秋游活动 班长提供了四个景点依次是 A B C D 每个学生只能选择一个景点 请统计出最终哪个景点想去的人数最多 利用Map集合进行统计 A06 HashMapDemo2 java package da
  • MySQL主从复制搭建步骤详解

    MySQL主从复制搭建步骤详解 1 简介 MySQL主从复制是一种数据库高可用性的解决方案 通过将数据从一个MySQL主服务器同步到一个或多个从服务器来提高数据库的可用性和性能 本文将详细介绍如何搭建MySQL主从复制环境 2 环境准备 在
  • linux下Nerdtree安装方法

    目录 1 下载Nerdtree 2 linux下安装 3 成功享受吧 1 下载Nerdtree 百度网盘下载 地址为链接 百度网盘 请输入提取码 提取码 07e3 来自百度网盘超级会员V4的分享 github方式下载 地址为 https g
  • 字符串 去掉空格 C++

    去掉空格 时间限制 1Sec 内存限制 128MB 提交 5807 解决 3117 题目描述 读入一些字符串 将其中的空格去掉 输入 输入为多行 每行为一个字符串 字符串只由字母 数字和空格组成 长度不超过80 输入以 End of fil
  • 【五、反向代理及其相关配置】

    文章目录 反向代理及其相关配置 1 反向代理 2 正向代理 3 网关 4 Nginx做反向代理的缺点 5 反向代理配置 1 跳转到外网网站上 2 跳转到本机服务器上 反向代理及其相关配置 1 反向代理 服务器提供的代理为反向代理 原理 当用
  • 网络安全(黑客)自学的误区

    一 自学网络安全学习的误区和陷阱 1 不要试图先成为一名程序员 以编程为基础的学习 再开始学习 我在之前的回答中 我都一再强调不要以编程为基础再开始学习网络安全 一般来说 学习编程不但学习周期长 而且实际向安全过渡后可用到的关键知识并不多
  • Trie树【数组实现】

    全文目录 Trie的表现形式 数组实现 Trie 树 代码 Trie的表现形式 Trie树主要用来实现字符串的存储和快速查找 其表现形式类似一颗多叉树 每个节点表示字符串的一个字符 由于可能会存在类似 abc 和 abcde 这样的数据 所
  • 大数据和人工智能到底是什么关系

    大数据和人工智能的关系 首先要说什么是大数据 这些年来 大数据先是被神化 继而又被妖魔化 到了今天 其实谁也不知道别人所谓的大数据指的是什么 有时候大数据的定义里既有平台 硬件 又有分析技术 但为了说清楚大数据和人工智能的关系 我们还是回归
  • 下一波加密浪潮:站在风口上的“NFT”!

    如果说2020是区块链的 Defi 大火年 流动性挖矿让不少用户和平台完美体验了一场红利盛宴 那么2021则杀出的黑马 NFT 升级为主角 拉开了表演的序幕 不少项目和用户目光纷纷投向这一赛道 试图寻找新的财富机遇 NFT定义 它究竟是什么
  • 特征脸EigenFace、Fisher脸FisherFace、LBP直方图LBPHFace

    在最新版的2 4 2中 文档的更新也是一大亮点 refrence manual扩充了200多页的内容 添加了contrib部分的文档 contrib就是指OpenCV中新添加的模块 但又不是很稳定 可以认为是一个雏形的部分 这次结合refm
  • 【NLP】使用 PyTorch 通过 Hugging Face 使用 BERT 和 Transformers 进行情感分析

    大家好 我是Sonhhxg 柒 希望你看完之后 能对你有所帮助 不足请指正 共同学习交流 个人主页 Sonhhxg 柒的博客 CSDN博客 欢迎各位 点赞 收藏 留言 系列专栏 机器学习 ML 自然语言处理 NLP 深度学习 DL fore
  • Android 项目必备(十二)--> APP 底部导航栏最佳实践

    文章目录 简介 TabLayout Fragment 1 效果图 2 布局文件 3 代码 BottomNavigationView Fragment 1 效果图 2 布局文件 3 main bottom navigation xml 4 代