編輯:關於Android編程
RadioGroup+ViewPager+Fragment實現的可滑動的Tab頁,非常的靈活。
最終效果圖
demo下載:http://download.csdn.net/download/shenyuanqing/9064189
部分源碼
MainActivity
package com.example.shen.tabtest.activity; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.view.ViewPager; import android.widget.RadioButton; import android.widget.RadioGroup; import com.example.shen.tabtest.R; import com.example.shen.tabtest.adapter.myFragmentPagerAdapter; import com.example.shen.tabtest.fragment.EvaluationFragment; import com.example.shen.tabtest.fragment.MerchantFragment; import com.example.shen.tabtest.fragment.OrderFragment; import java.util.ArrayList; public class MainActivity extends FragmentActivity implements RadioGroup.OnCheckedChangeListener{ private ViewPager viewPager; private RadioGroup radioGroup; private RadioButton rbOrder,rbEvaluation,rbMerchant; private ArrayListactivity_main.xmlalFragment; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //初始化界面組件 initView(); //初始化ViewPager initViewPager(); } private void initView(){ viewPager=(ViewPager) findViewById(R.id.viewpager); radioGroup=(RadioGroup) findViewById(R.id.radiogroup); rbOrder=(RadioButton) findViewById(R.id.rb_order); rbEvaluation=(RadioButton) findViewById(R.id.rb_evaluation); rbMerchant=(RadioButton) findViewById(R.id.rb_merchant); radioGroup.setOnCheckedChangeListener(this); } private void initViewPager(){ OrderFragment orderFragment=new OrderFragment(); EvaluationFragment evaluationFragment=new EvaluationFragment(); MerchantFragment merchantFragment=new MerchantFragment(); alFragment=new ArrayList<>(); alFragment.add(orderFragment); alFragment.add(evaluationFragment); alFragment.add(merchantFragment); //ViewPager設置適配器 viewPager.setAdapter(new myFragmentPagerAdapter(getSupportFragmentManager(), alFragment)); //ViewPager顯示第一個Fragment viewPager.setCurrentItem(0); //ViewPager頁面切換監聽 viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } //滑動ViewPager,RadioButton選中狀態做相應變換 @Override public void onPageSelected(int position) { switch (position){ case 0: radioGroup.check(R.id.rb_order); break; case 1: radioGroup.check(R.id.rb_evaluation); break; case 2: radioGroup.check(R.id.rb_merchant); break; } } @Override public void onPageScrollStateChanged(int state) { } }); } /** * 點擊RadioButton切換ViewPager中相應的Fragment * @param group * @param checkedId */ @Override public void onCheckedChanged(RadioGroup group, int checkedId) { switch (checkedId){ case R.id.rb_order: viewPager.setCurrentItem(0,false); break; case R.id.rb_evaluation: viewPager.setCurrentItem(1,false); break; case R.id.rb_merchant: viewPager.setCurrentItem(2,false); break; } } }
myFragmentPagerAdapter
package com.example.shen.tabtest.adapter; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; import java.util.ArrayList; /** * Created by Administrator on 2015/6/24. */ public class myFragmentPagerAdapter extends FragmentPagerAdapter { private ArrayListstyle_radiobuttonlist; public myFragmentPagerAdapter(FragmentManager fm, ArrayList list){ super(fm); this.list=list; } @Override public Fragment getItem(int position) { return list.get(position); } @Override public int getCount() { return list.size(); } }
activity的啟動流程加載一個Activity肯定不會像加載一般的類那樣,因為activity作為系統的組件有自己的生命周期,有系統的很多回調控制,所以自定義一個De
OpenCV中強大的Mat類型大家已經比較熟悉了。這裡梳理一些在工程中其他經常用到的幾種基本數據類型。包括:VecScalarPointSizeRectRotatedRe
由於Linux系統的權限限制和Android封裝架構限制,很多涉及底層設備、接口、驅動控制的應用開發,不得不使用到本文的NDK開發環境(基於Android源碼或內核源碼修
一.申請密鑰登陸百度開放平台,選擇創建應用,輸入應用名稱,選擇AndroidSDK、發布版SHA1值和包名 獲取sha1值– 使用AndroidStudio獲