編輯:關於android開發
主要還是想實現滑動的tab切換效果
MainActivity.java
package com.example.csdn; import com.viewpagerindicator.TabPageIndicator; import android.os.Bundle; import android.support.v4.app.Fragment; 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.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; public class MainActivity extends FragmentActivity { private TabPageIndicator tpi_tab; private ViewPager vp_content; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tpi_tab = (TabPageIndicator) findViewById(R.id.vpi_tab); vp_content = (ViewPager) findViewById(R.id.vp_content); FragmentManager fm = getSupportFragmentManager(); TabAdapter adapter = new TabAdapter(fm); // ViewPager設置適配器 vp_content.setAdapter(adapter); // 指示器綁定ViewPager tpi_tab.setViewPager(vp_content, 0); } } /** * 標簽部分適配器 * * @author taoshihan * */ class TabAdapter extends FragmentPagerAdapter { public static final String[] TITLES = new String[] { "業界", "移動", "研發","PHP","Android","Java","前端" }; public TabAdapter(FragmentManager fm) { super(fm); } @Override public Fragment getItem(int arg0) { return new ContentFragment(arg0); } @Override public int getCount() { return TITLES.length; } @Override public CharSequence getPageTitle(int position) { // TODO Auto-generated method stub return TITLES[position % TITLES.length]; } } /** * 內容部分 * @author taoshihan * */ class ContentFragment extends Fragment{ private int index; public ContentFragment(int index) { this.index=index; } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view=View.inflate(getActivity(), R.layout.main_content, null); TextView tv_content=(TextView) view.findViewById(R.id.tv_content); String[] titles=TabAdapter.TITLES; tv_content.setText(titles[index]); return view; } }
樣式就是在清單文件中給activity填上主題
<activity android:name=".MainActivity" android:label="@string/app_name" android:theme="@style/Theme.PageIndicatorDefaults"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>
一起來學習Android自定義控件 概述 Android已經為我們提供了大量的View供我們使用,但是可能有時候這些組件不能滿足我們的需求,這時候就需要自定義控件了。
Visual Studio Emulator for Android 初體驗,emulatorandroidVisual Studio Emulator for Andr
Android事件分發 Android 中與 Touch 事件相關的方法包括:dispatchTouchEvent(MotionEvent ev)、onInterce
硅谷商城6--購物車編輯實現,硅谷商城6--購物車 完成狀態