一切為了快速開發(fā)
開發(fā)類似界面
背景:
文字顏色:
開發(fā)類似界面
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;//頁數(shù)
private int curPosition=0;//當(dāng)前頁
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快速搭建頁面結(jié)構(gòu)
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061
微信掃一掃加我為好友
QQ號聯(lián)系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元

