這是主activity:
黔西南州ssl適用于網(wǎng)站、小程序/APP、API接口等需要進行數(shù)據(jù)傳輸應用場景,ssl證書未來市場廣闊!成為創(chuàng)新互聯(lián)公司的ssl證書銷售渠道,可以享受市場價格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:13518219792(備注:SSL證書合作)期待與您的合作!
public class BActivity extends Activity {
private ViewPager viewPager;
private TextView text, text2, text3;
private MyViewPager myPager;
private List
private View view1, view2, view3;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
initText();
initViewPager();
}
//初始化textView
public void initText() {
text = (TextView) findViewById(R.id.text);
text2 = (TextView) findViewById(R.id.text2);
text3 = (TextView) findViewById(R.id.text3);
text.setOnClickListener(new MyOnClickListerImpl(0));
text2.setOnClickListener(new MyOnClickListerImpl(1));
text3.setOnClickListener(new MyOnClickListerImpl(2));
}
//TextView的監(jiān)聽事件
private class MyOnClickListerImpl implements OnClickListener {
int index = 0 ;
public MyOnClickListerImpl(int i){
index = i ;
}
@Override
public void onClick(View v) {
viewPager.setCurrentItem(index);
}
}
//初始化viewPager
public void initViewPager() {
viewPager = (ViewPager) findViewById(R.id.viewPager);
view1 = LayoutInflater.from(BActivity.this).inflate(
R.layout.show_content, null);
view2 = LayoutInflater.from(BActivity.this).inflate(
R.layout.show_content2, null);
view3 = LayoutInflater.from(BActivity.this).inflate(
R.layout.show_content3, null);
mList = new ArrayList
mList.add(view1);
mList.add(view2);
mList.add(view3);
myPager = new MyViewPager(mList);
viewPager.setAdapter(myPager);
viewPager.setCurrentItem(0);
viewPager.setOnPageChangeListener(new OnPageChangeListenerImpl());
}
private class OnPageChangeListenerImpl implements OnPageChangeListener {
@Override
public void onPageScrollStateChanged(int arg0) {
/*
* 此方法是改變狀態(tài)的時候調(diào)用,arg0有三個值,分別是0、1、2 當為0的時候說明說明都沒做, 當為1的時候說明正在滑動
* 當為2的時候說明已經(jīng)滑動完成
*/
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
/*
* 這個方法是滑動的時候調(diào)用的, 第一個參數(shù)是當前頁面 ,第二個參數(shù)是當前頁面偏移的百分比, 第三個頁面是當前頁面偏移的像素位置
*/
}
@Override
public void onPageSelected(int arg0) {
// 此方法是頁面跳轉完成之后調(diào)用,參數(shù)的意思是,當前旋轉的position,點擊選中的position
switch (arg0) {
case 0:
text.setTextColor(getResources().getColor(R.color.whi));
text2.setTextColor(getResources().getColor(R.color.back));
text3.setTextColor(getResources().getColor(R.color.back));
break;
case 1:
text.setTextColor(getResources().getColor(R.color.back));
text2.setTextColor(getResources().getColor(R.color.whi));
text3.setTextColor(getResources().getColor(R.color.back));
break;
case 2:
text.setTextColor(getResources().getColor(R.color.back));
text2.setTextColor(getResources().getColor(R.color.back));
text3.setTextColor(getResources().getColor(R.color.whi));
break;
default:
break;
}
}
}
這是main.xml:
android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#FFFFFF" > android:id="@+id/line" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:background="#888888" > android:id="@+id/text" android:layout_width="0sp" android:layout_height="wrap_content" android:layout_margin="10sp" android:layout_weight="1" android:gravity="center_horizontal" android:text="關卡一" android:textColor="#FFFFFF" android:textSize="20sp" /> android:id="@+id/text2" android:layout_width="0sp" android:layout_height="wrap_content" android:layout_margin="10sp" android:layout_weight="1" android:gravity="center_horizontal" android:text="關卡二" android:textColor="#000000" android:textSize="20sp" /> android:id="@+id/text3" android:layout_width="0sp" android:layout_height="wrap_content" android:layout_margin="10sp" android:layout_weight="1" android:gravity="center_horizontal" android:text="關卡三" android:textColor="#000000" android:textSize="20sp" /> android:id="@+id/viewPager" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@id/line" />
這是MyViewPager:
package your.namespace;
import java.util.List;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
public class MyViewPager extends PagerAdapter {
private List
public MyViewPager(List
this.mList = mList;
}
@Override
public int getCount() {
// 返回mList中包含view的所有view的個數(shù)
return mList.size();
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
// 刪除mList中的某一個view
container.removeView(mList.get(position));
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
// 添加一個view到mList中
container.addView(mList.get(position), 0);
return mList.get(position);
}
@Override
public boolean isViewFromObject(View arg0, Object arg1) {
return arg0 == arg1;
}
}