<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
tools:context=".activity.SettingActivity">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">
<RadioGroup
android:id="@+id/radio_group"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="7">
<RadioButton
android:id="@+id/fiy_parameter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/button_select"
android:button="@null"
android:checked="true" />
<RadioButton
android:id="@+id/perception"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/button_select"
android:button="@null" />
<RadioButton
android:id="@+id/remote_control"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/button_select"
android:button="@null" />
<RadioButton
android:id="@+id/transfer_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/button_select"
android:button="@null" />
<RadioButton
android:id="@+id/cell_message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/button_select"
android:button="@null" />
<RadioButton
android:id="@+id/cloud_platform"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/button_select"
android:button="@null" />
<RadioButton
android:id="@+id/general"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/button_select"
android:button="@null" />
</RadioGroup>
</LinearLayout>
<View
android:layout_width="1dp"
android:layout_height="wrap_content"
android:background="@color/black"></View>
<com.bjdj.droneflyV5.view.NoSwipeViewPager
android:id="@+id/viewPage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></com.bjdj.droneflyV5.view.NoSwipeViewPager>
</LinearLayout>
随便用两个图片 在res ->drawble下面创建button_select.xml文件
android:background="@drawable/button_select"
用于选中不选择底部按钮图片切换
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:drawable="@mipmap/playback_ic_selected"/>
<item android:state_checked="false" android:drawable="@mipmap/playback_ic_unselected"/>
</selector>
public class SettingActivity extends BaseActivity {
private NoSwipeViewPager viewPager;
private RadioGroup radio_group;
private RadioButton fiyParamenter, perception, remoteControl, transferImage, cellMessage, cloudPlatform, general;
ArrayList<Fragment> fragments;
FlyParameterFragment flyParameterFragment;
PerceptualFragment perceptualFragment;
RemoteControlFragment remoteControlFragment;
TransferImageFragment transferImageFragment;
CellMessageFragment cellMessageFragment;
CloudPlatformFragment cloudPlatformFragment;
GeneralFragment generalFragment;
FragmentManager fm;
private int positon = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
RxBarTool.hideStatusBar(this);
setContentView(R.layout.activity_setting);
initview();
viewPagerWay();
changeSelect(positon);
initOnclick();
}
private void initview() {
viewPager = (NoSwipeViewPager) findViewById(R.id.viewPage);
radio_group = (RadioGroup) findViewById(R.id.radio_group);
fiyParamenter = (RadioButton) findViewById(R.id.fiy_parameter);
perception = (RadioButton) findViewById(R.id.perception);
remoteControl = (RadioButton) findViewById(R.id.remote_control);
transferImage = (RadioButton) findViewById(R.id.transfer_image);
cellMessage = (RadioButton) findViewById(R.id.cell_message);
cloudPlatform = (RadioButton) findViewById(R.id.cloud_platform);
general = (RadioButton) findViewById(R.id.general);
fragments = new ArrayList<Fragment>();
fm = getSupportFragmentManager();
flyParameterFragment = new FlyParameterFragment();
perceptualFragment = new PerceptualFragment();
remoteControlFragment = new RemoteControlFragment();
transferImageFragment = new TransferImageFragment();
cellMessageFragment = new CellMessageFragment();
cloudPlatformFragment = new CloudPlatformFragment();
generalFragment = new GeneralFragment();
fragments.add(flyParameterFragment);
fragments.add(perceptualFragment);
fragments.add(remoteControlFragment);
fragments.add(transferImageFragment);
fragments.add(cellMessageFragment);
fragments.add(cloudPlatformFragment);
fragments.add(generalFragment);
viewPager.setCanSwipe(false);
}
private void viewPagerWay() {
viewPager.setAdapter(new FragmentPagerAdapter(fm) {
@Override
public Fragment getItem(int position) {
return fragments.get(position);
}
@Override
public int getCount() {
return fragments.size();
}
});
viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@SuppressLint("ResourceAsColor")
@Override
public void onPageSelected(int position) {
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
}
private void changeSelect(int positon) {
switch (positon) {
case 0:
fiyParamenter.setChecked(true);
viewPager.setCurrentItem(0);
break;
case 1:
perception.setChecked(true);
viewPager.setCurrentItem(1);
break;
case 2:
remoteControl.setChecked(true);
viewPager.setCurrentItem(2);
break;
case 3:
transferImage.setChecked(true);
viewPager.setCurrentItem(3);
break;
case 4:
cellMessage.setChecked(true);
viewPager.setCurrentItem(4);
break;
case 5:
cloudPlatform.setChecked(true);
viewPager.setCurrentItem(5);
break;
case 6:
general.setChecked(true);
viewPager.setCurrentItem(6);
break;
}
}
private void initOnclick() {
radio_group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId) {
case R.id.fiy_parameter:
viewPager.setCurrentItem(0);
break;
case R.id.perception:
viewPager.setCurrentItem(1);
break;
case R.id.remote_control:
viewPager.setCurrentItem(2);
break;
case R.id.transfer_image:
viewPager.setCurrentItem(3);
break;
case R.id.cell_message:
viewPager.setCurrentItem(4);
break;
case R.id.cloud_platform:
viewPager.setCurrentItem(5);
break;
case R.id.general:
viewPager.setCurrentItem(6);
break;
}
}
});
}
}
changeSelect(positon);简单实现该方法可以删除,这里是实现通过activityA 跳转到另一个acitivityB里面指定第几个fragment