亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

RadioButton+ViewPager+FragmentPagerAdapter快

系統 1665 0
一切為了快速開發

開發類似界面
RadioButton+ViewPager+FragmentPagerAdapter快速搭建頁面結構

    
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.RadioButton;

import com.yirui.youbao.App;
import com.yirui.youbao.fragment.ParkingPayedListFragment;
import com.yirui.youbao.fragment.ParkingUnpayListFragment;

/**
 * 
 * @author pythoner
 *
 */
public class ParkingPayActivity extends BaseActivity implements View.OnClickListener{

	private final int count = 2;//頁數
	private int curPosition=0;//當前頁
	private RadioButton[] rbs;
	private ViewPager viewPager;
	private FragmentPagerAdapter pagerAdapter;
	private Fragment[] fragments;
    
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_parking_pay);
		initActionBar("App付費");
		initViews();
	}
	
	private void initViews() {
		initIndicator();
		initViewPager();
	}

	private void initIndicator(){
		rbs = new RadioButton[count];
		rbs[0] = (RadioButton) findViewById(R.id.rb_0);
		rbs[1] = (RadioButton) findViewById(R.id.rb_1);

		for (int i = 0; i < rbs.length; i++) {
			rbs[i].setOnClickListener(new View.OnClickListener() {

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					String tag = (String) v.getTag();
					curPosition=Integer.parseInt(tag);
					viewPager.setCurrentItem(curPosition);
				}
			});
		}
		
		rbs[curPosition].setChecked(true);
	}
	
	private void initViewPager(){
		fragments = new Fragment[count];
		fragments[0] = ParkingUnpayListFragment.newInstance();
		fragments[1] = ParkingPayedListFragment.newInstance();

		pagerAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
			@Override
			public int getCount() {
				return fragments.length;
			}

			@Override
			public Fragment getItem(int position) {
				return fragments[position];
			}

		};

		viewPager = (ViewPager) findViewById(R.id.viewPager);
		viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

			@Override
			public void onPageSelected(int position) {
				// TODO Auto-generated method stub
				rbs[position].setChecked(true);
				curPosition=position;
			}

			@Override
			public void onPageScrolled(int arg0, float arg1, int arg2) {
				// TODO Auto-generated method stub
			}

			@Override
			public void onPageScrollStateChanged(int arg0) {
				// TODO Auto-generated method stub

			}
		});

		viewPager.setAdapter(pagerAdapter);
		viewPager.setCurrentItem(curPosition);
	}
	
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
	}
	
}

  


    
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/bg_gray"
    android:orientation="vertical" >

    <include layout="@layout/actionbar_comm" />

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/white"
        android:padding="8dp" >

        <RadioGroup
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:orientation="horizontal" >

            <RadioButton
                android:id="@+id/rb_0"
                android:tag="0"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/bg_blue_trans_with_frame"
                android:button="@null"
                android:paddingBottom="4dp"
                android:paddingLeft="8dp"
                android:paddingRight="8dp"
                android:paddingTop="4dp"
                android:text="未付費"
                android:textColor="@color/textcolor_blue_white_radio" />

            <RadioButton
                android:id="@+id/rb_1"
                android:tag="1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/bg_blue_trans_with_frame"
                android:button="@null"
                android:paddingBottom="4dp"
                android:paddingLeft="8dp"
                android:paddingRight="8dp"
                android:paddingTop="4dp"
                android:text="已付費"
                android:textColor="@color/textcolor_blue_white_radio" />
        </RadioGroup>
    </FrameLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/viewPager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:flipInterval="30"
        android:background="@android:color/white"
        android:layout_marginTop="16dp"
        android:persistentDrawingCache="animation" />

</LinearLayout>

  


背景:
    
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_checked="true">
        <shape>
            <solid android:color="@color/primary" />
            <stroke android:width="1dp" android:color="@color/primary" />
            <corners android:topLeftRadius="dp" android:topRightRadius="0dp" android:bottomLeftRadius="0dp" android:bottomRightRadius="0dp"/>
        </shape>
   	</item>
    <item>
        <shape>
            <solid android:color="@android:color/transparent" />
            <stroke android:width="1dp" android:color="@color/primary" />
            <corners android:topLeftRadius="dp" android:topRightRadius="0dp" android:bottomLeftRadius="0dp" android:bottomRightRadius="0dp"/>
        </shape>
    </item>

</selector>

  


文字顏色:
    
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="true" android:color="@android:color/white" />
    <item android:color="@color/primary" />
</selector>

  

RadioButton+ViewPager+FragmentPagerAdapter快速搭建頁面結構


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 久久天天躁日日躁狠狠躁 | 日日操夜夜操视频 | 一本一道 | 欧美成人视 | 欧美日本高清动作片www网站 | 国产操女人 | 欧美一级毛片在线播放 | 色欧美在线视频 | 亚洲国产二区三区久久 | 日韩美毛片 | 亚洲精品欧美精品中文字幕 | 99热8| 久久久久久久久中文字幕 | 一道精品视频一区二区三区图片 | 老司机精品在线观看 | 欧美洲精品亚洲精品中文字幕 | 免费的黄色网 | 精品中文字幕乱码一区二区 | 欧美成人性videos | 午夜大片免费男女爽爽影院久久 | videos欧美黑白爆交 | 欧美一区二区三区视频 | xxxx免费观看 | 99资源在线 | 亚洲国产成人精品一区91 | 欧美日韩亚洲无线码在线观看 | www4虎| 久久久久久综合成人精品 | 久久综合九色综合欧洲 | 婷婷在线综合 | 欧美大香a蕉免费 | 国产成人综合亚洲亚洲欧美 | 欧美乱码 | 手机看黄av免费网址 | 欧美色视频日本片高清在线观看 | 欧美专区在线观看 | 四虎国产精品视频免费看 | 久精品视频村上里沙 | 国产成人丝袜网站在线看 | 欧美日本在线视频 | 麻豆国产在线观看一区二区 |