在我们大学生的日常生活中,很多时候不知道如何去规划自己的安排,同时也不知道自己的钱用向何方,但我们又不想通过传统的那种写在纸上的记账方法,
显得十分的累赘和繁琐,甚至到了一定的时间找不到本子和不想记了。而如今在这个互联网高速发展的时代,手机是生活中不可缺少的东西,甚至越来越热的趋
势,而一个小小的记账本app就能很好的帮助我们更好的来管理自己的安排。这个app更多的是借鉴了微信的模型和网上的代码,有很多不完善的一些地方,还
需要更多的改善,存在闪退的原因还在逐步修改之中。
接下来是fragment和activity的界面布局。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#eee" android:orientation="vertical" android:weightSum="1"> <LinearLayout android:layout_width="fill_parent" android:layout_height="50dp" android:background="#628fd0"> </LinearLayout> <android.support.v4.view.ViewPager android:id="@+id/id_viewpager" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="0.97" > </android.support.v4.view.ViewPager> <include layout="@layout/bottom_bar" /> </LinearLayout>
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/ly_main_tab_bottom" android:layout_width="fill_parent" android:layout_height="70dp" android:layout_alignParentBottom="true" android:background="@drawable/tar_bar1" > <!--android:background="@drawable/bottom_bar" >--> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" > <LinearLayout android:id="@+id/id_tab_bottom_weixin" android:layout_width="0dp" android:layout_height="fill_parent" android:layout_weight="1" android:descendantFocusability="beforeDescendants" android:gravity="center" android:orientation="vertical" > <ImageButton android:id="@+id/btn_tab_bottom_weixin" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="#0000" android:clickable="false" android:src="@drawable/tab_weixin_pressed" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="账户" /> </LinearLayout> <LinearLayout android:id="@+id/id_tab_bottom_friend" android:layout_width="0dp" android:layout_height="fill_parent" android:layout_weight="1" android:descendantFocusability="beforeDescendants" android:gravity="center" android:orientation="vertical" > <ImageButton android:id="@+id/btn_tab_bottom_friend" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="#0000" android:clickable="false" android:src="@drawable/tab_find_frd_normal" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="计划详情" /> </LinearLayout> <LinearLayout android:id="@+id/id_tab_bottom_contact" android:layout_width="0dp" android:layout_height="fill_parent" android:layout_weight="1" android:descendantFocusability="beforeDescendants" android:gravity="center" android:orientation="vertical" > <ImageButton android:id="@+id/btn_tab_bottom_contact" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="#0000" android:clickable="false" android:src="@drawable/tab_address_normal" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="多记计" /> </LinearLayout> <LinearLayout android:id="@+id/id_tab_bottom_setting" android:layout_width="0dp" android:layout_height="fill_parent" android:layout_weight="1" android:descendantFocusability="beforeDescendants" android:gravity="center" android:orientation="vertical" > <ImageButton android:id="@+id/btn_tab_bottom_setting" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="#0000" android:clickable="false" android:src="@drawable/tab_settings_normal" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="我" /> </LinearLayout> </LinearLayout> </RelativeLayout>
接下来是他主界面代码的实现,首先是MainActivity.java
public class MainActivity extends FragmentActivity implements View.OnClickListener { private View.OnClickListener onclicklistene; private ViewPager mViewPager; private FragmentPagerAdapter mAdapter; private List<Fragment> mFragments = new ArrayList<Fragment>(); /** * 底部四个按钮 */ private LinearLayout mTabBtnWeixin; private LinearLayout mTabBtnFrd; private LinearLayout mTabBtnAddress; private LinearLayout mTabBtnSettings; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mViewPager = (ViewPager) findViewById(R.id.id_viewpager); initView(); findViewById(R.id.btn_tab_bottom_weixin).setOnClickListener(this); findViewById(R.id.btn_tab_bottom_contact).setOnClickListener(this); findViewById(R.id.btn_tab_bottom_friend).setOnClickListener(this); findViewById(R.id.btn_tab_bottom_setting).setOnClickListener(this); mAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) { @Override public int getCount() { return mFragments.size(); } @Override public Fragment getItem(int arg0) { return mFragments.get(arg0); } }; mViewPager.setAdapter(mAdapter); mViewPager.addOnPageChangeListener(new OnPageChangeListener() { private int currentIndex; @Override public void onPageSelected(int position) { resetTabBtn(); switch (position) { case 0: ((ImageButton) mTabBtnWeixin.findViewById(R.id.btn_tab_bottom_weixin)) .setImageResource(R.drawable.tab_weixin_pressed); break; case 1: ((ImageButton) mTabBtnFrd.findViewById(R.id.btn_tab_bottom_friend)) .setImageResource(R.drawable.tab_find_frd_pressed); break; case 2: ((ImageButton) mTabBtnAddress.findViewById(R.id.btn_tab_bottom_contact)) .setImageResource(R.drawable.tab_address_pressed); break; case 3: ((ImageButton) mTabBtnSettings.findViewById(R.id.btn_tab_bottom_setting)) .setImageResource(R.drawable.tab_settings_pressed); break; } currentIndex = position; } @Override public void onPageScrolled(int arg0, float arg1, int arg2) { } @Override public void onPageScrollStateChanged(int arg0) { } }); } protected void resetTabBtn() { ((ImageButton) mTabBtnWeixin.findViewById(R.id.btn_tab_bottom_weixin)) .setImageResource(R.drawable.tab_weixin_normal); ((ImageButton) mTabBtnFrd.findViewById(R.id.btn_tab_bottom_friend)) .setImageResource(R.drawable.tab_find_frd_normal); ((ImageButton) mTabBtnAddress.findViewById(R.id.btn_tab_bottom_contact)) .setImageResource(R.drawable.tab_address_normal); ((ImageButton) mTabBtnSettings.findViewById(R.id.btn_tab_bottom_setting)) .setImageResource(R.drawable.tab_settings_normal); } private void initView() { mTabBtnWeixin = (LinearLayout) findViewById(R.id.id_tab_bottom_weixin); mTabBtnFrd = (LinearLayout) findViewById(R.id.id_tab_bottom_friend); mTabBtnAddress = (LinearLayout) findViewById(R.id.id_tab_bottom_contact); mTabBtnSettings = (LinearLayout) findViewById(R.id.id_tab_bottom_setting); FragmentAccount fragmentaccount = new FragmentAccount(); FragmentFind fragmentfind = new FragmentFind(); FragmentPlan fragmentplan = new FragmentPlan(); MainTab04 tab04 = new MainTab04(); mFragments.add(fragmentaccount); mFragments.add(fragmentplan); mFragments.add(fragmentfind); mFragments.add(tab04); } public void onClick(View v) { switch (v.getId()) { case R.id.btn_tab_bottom_weixin: mViewPager.setCurrentItem(0, true); break; case R.id.btn_tab_bottom_friend: mViewPager.setCurrentItem(1, true); break; case R.id.btn_tab_bottom_contact: mViewPager.setCurrentItem(2, true); break; case R.id.btn_tab_bottom_setting: mViewPager.setCurrentItem(3, true); break; } } }