Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the bottom sliding menu of Meituan APP by Android

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly shows you "Android how to achieve Meituan APP bottom slide menu", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to achieve Meituan APP bottom slide menu" this article.

In the current APP applications, similar to the bottom slide menu of Meituan APP, there are many applications, such as QQ, Wechat and Alipay. The development process is as follows

1. Bottom button

The bottom button uses RadioButton.

/ / Button layout

/ / style style match_parent 60dp center 1 @ null @ drawable/menueselector

The menueselector in the style style is the background selector to change the color when the button is selected.

Create a new folder (drawable-nodpi) under the Res directory, create a new xml file in it, select the selector with the resource type Drawable, and create the item option in each selector

two。 Sliding window in the middle

3. Add the Fragment corresponding to the button to the sliding window and listen for the corresponding event

The following code pays attention to two points

MainActivity needs to inherit from FragmentActivity, so that you can find the getSupportFragmentManager () method. Remember to introduce android.support.v4.app.Fragment instead of android.app.Fragment when writing Fragment. (android.app.Fragment was introduced in 3.0, and android.support.v4.app.Fragment is preferred for compatibility with earlier versions.)

Package com.lsw.wealthapp.activity;import android.support.v4.app.Fragment;import android.os.Bundle;import android.support.v4.app.FragmentActivity;import android.support.v4.app.FragmentManager;import android.support.v4.app.FragmentPagerAdapter;import android.support.v4.view.ViewPager;import android.widget.RadioButton;import android.widget.RadioGroup;import com.lsw.wealthapp.R;import com.lsw.wealthapp.fragment.CaptureFragment;import com.lsw.wealthapp.fragment.HomeFragment;import com.lsw.wealthapp.fragment.InvestmentFragment Import com.lsw.wealthapp.fragment.MoreFragment;import com.lsw.wealthapp.fragment.MyFragment;import java.util.ArrayList;import java.util.List;public class MainActivity extends FragmentActivity {/ / HomeFragmentIndex private static final int HomeViewPagerIndex = 0; / / InvestmentFragmentIndex private static final int InvsetViewPagerIndex = 1; / / CaptureFragmentIndex private static final int CaptureViewPagerIndex = 2; / / MyFragmentIndex private static final int MyViewPagerIndex = 3; / / MoreFragmentIndex private static final int MoreViewPagerIndex = 4; private ViewPager viewPager; / / Home page private HomeFragment homeFragment; / / Investment page private InvestmentFragment investmentFragment / / Photo Page private CaptureFragment captureFragment; / / my Page private MyFragment myFragment; / / more pages private MoreFragment moreFragment; / / Fragment Collection private List fragmentList; / / FragmentAdapter private MyPageFramgentAdapter myPageFramgentAdapter; / / menu RadioGroup private RadioGroup radioGroup; / / Home button private RadioButton rbtnHome; / / Investment button private RadioButton rbtnInvest; / / Photo button private RadioButton rbtnCapture; / / my button private RadioButton rbtnMine; / / more button private RadioButton rbtnMore @ Override protected void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.activity_main); initViews ();} private void initViews () {viewPager = (ViewPager) findViewById (R.id.viewPager); homeFragment = new HomeFragment (); investmentFragment = new InvestmentFragment (); captureFragment = new CaptureFragment (); myFragment = new MyFragment (); moreFragment = new MoreFragment (); fragmentList = new ArrayList (); radioGroup = (RadioGroup) findViewById (R.id.rg_menu); rbtnHome = (RadioButton) findViewById (R.id.rbtn_home) RbtnInvest = (RadioButton) findViewById (R.id.rbtn_vest); rbtnCapture = (RadioButton) findViewById (R.id.rbtn_photo); rbtnMine = (RadioButton) findViewById (R.id.rbtn_mine); rbtnMore = (RadioButton) findViewById (R.id.rbtn_more); / / when the button is selected, viewPager displays the corresponding page radioGroup.setOnCheckedChangeListener (new RadioGroup.OnCheckedChangeListener () {@ Override public void onCheckedChanged (RadioGroup radioGroup, int I) {switch (I) {case R.id.rbtn_home: viewPager.setCurrentItem (HomeViewPagerIndex); break Case R.id.rbtn_vest: viewPager.setCurrentItem (InvsetViewPagerIndex); break; case R.id.rbtn_photo: viewPager.setCurrentItem (CaptureViewPagerIndex); break; case R.id.rbtn_mine: viewPager.setCurrentItem (MyViewPagerIndex); break; case R.id.rbtn_more: viewPager.setCurrentItem (MoreViewPagerIndex); break;}); / / add Fragment to the collection fragmentList.add (homeFragment); fragmentList.add (investmentFragment); fragmentList.add (captureFragment); fragmentList.add (myFragment); fragmentList.add (moreFragment); FragmentManager fm = getSupportFragmentManager () MyPageFramgentAdapter = new MyPageFramgentAdapter (fm); viewPager.setAdapter (myPageFramgentAdapter); / / viewPager changes and the corresponding button state becomes selected viewPager.setOnPageChangeListener (new ViewPager.OnPageChangeListener () {@ Override public void onPageScrolled (int position, float positionOffset, int positionOffsetPixels) {} @ Override public void onPageSelected (int position) {switch (position) {case HomeViewPagerIndex: rbtnHome.setChecked (true); break; case InvsetViewPagerIndex: rbtnInvest.setChecked (true); break; case CaptureViewPagerIndex: rbtnCapture.setChecked (true); break; case MyViewPagerIndex: rbtnMine.setChecked (true)) Break; case MoreViewPagerIndex: rbtnMore.setChecked (true); break; default: break;}} @ Override public void onPageScrollStateChanged (int state) {});} / / class MyPageFramgentAdapter extends FragmentPagerAdapter {public MyPageFramgentAdapter (FragmentManager fm) {super (fm);} @ Override public Fragment getItem (int position) {return fragmentList.get (position);} @ Override public int getCount () {return fragmentList.size ();}

The above is all the contents of the article "how to realize the bottom sliding menu of Meituan APP by Android". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report