引导界面——ViewPager+View

//actvity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="app.jiyun.com.android_yindao_demo.MainActivity">

    <android.support.v4.view.ViewPager
        android:id="@+id/ViewPager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"></android.support.v4.view.ViewPager>

    <RadioGroup
        android:id="@+id/RadioGroup"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="30dp"
        android:orientation="horizontal">

        <RadioButton
            android:id="@+id/Radio_one"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:background="@drawable/radio_style"
            android:button="@null" />

        <RadioButton
            android:id="@+id/Radio_Two"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:background="@drawable/radio_style"
            android:button="@null" />

        <RadioButton
            android:id="@+id/Radio_Three"
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:background="@drawable/radio_style"
            android:button="@null" />
    </RadioGroup>

</RelativeLayout>
 

//radio_style的xml详细设置

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

    //被点击(按压)的时候
    <item android:drawable="@drawable/radio_shape" android:state_pressed="true" />

    //被选中的时候
    <item android:drawable="@drawable/radio_shape" android:state_checked="true" />

    //被聚焦的时候
    <item android:drawable="@drawable/radio_shape" android:state_focused="true" />

    //默认
    <item android:drawable="@drawable/radio_no_shape" />
</selector>

 

//按钮的shape设置

(1)<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <corners android:radius="15dp" />
    <solid android:color="@color/colorPrimary" />
</shape>

(2)<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <corners android:radius="15dp" />
    <solid android:color="@color/colorAccent" />
</shape>

 

//主界面的Java代码

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    private ViewPager ViewPager;
    private RadioGroup RadioGroup;
    private ArrayList<View> mList = new ArrayList<>();
    private Button mBtn;
    private SharedPreferences mShare;
    private SharedPreferences.Editor mEditor;
    private Context mContext = MainActivity.this;
  

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

        mShare = mContext.getSharedPreferences("user",MODE_PRIVATE);
        //编辑器
        mEditor = mShare.edit();
        boolean isTrue = mShare.getBoolean("isTrue", false);
        if (isTrue){
            Intent intent = new Intent(MainActivity.this, TestActivity.class);
            startActivity(intent);
            finish();
        }
        initView();
    }

    private void initView() {
        ViewPager = (ViewPager) findViewById(R.id.ViewPager);
        RadioGroup = (RadioGroup) findViewById(R.id.RadioGroup);
        View one = getLayoutInflater().inflate(R.layout.view_one, null);
        View two = getLayoutInflater().inflate(R.layout.view_two, null);
        View three = getLayoutInflater().inflate(R.layout.view_three, null);
        mBtn = (Button) three.findViewById(R.id.ViewThree_Btn);
        mBtn.setOnClickListener(this);
        mList.add(one);
        mList.add(two);
        mList.add(three);
        MyViewPagerAdapter myViewPagerAdapter = new MyViewPagerAdapter(mList);
        ViewPager.setAdapter(myViewPagerAdapter);
        RadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId) {
                    case R.id.Radio_one:
                        ViewPager.setCurrentItem(0);
                        break;
                    case R.id.Radio_Two:
                        ViewPager.setCurrentItem(1);
                        break;
                    case R.id.Radio_Three:
                        ViewPager.setCurrentItem(2);
                        break;
                }
            }
        });
        ViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                RadioButton rb = (RadioButton) RadioGroup.getChildAt(position);
                rb.setChecked(true);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ViewThree_Btn:
                mEditor.putBoolean("isTrue",true);
                mEditor.commit();
                Intent intent = new Intent(MainActivity.this, TestActivity.class);
                startActivity(intent);
                finish();
                break;
        }
    }
}
 

转载于:https://my.oschina.net/u/3730650/blog/1577333

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值