精华内容
下载资源
问答
  • FrameLayout切换

    2019-04-06 21:26:49
    //点击切换 radio_group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { FragmentTransaction ...

    public class MainActivity extends AppCompatActivity {

    private RadioGroup radio_group;
    private FragmentManager manager;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //初始化
        radio_group = findViewById(R.id.radio_group);
        //获取适配器
        manager = getSupportFragmentManager();
        final Frag01 frag01 = new Frag01();
        final Frag02 frag02 = new Frag02();
        manager.beginTransaction().add(R.id.fragment_layout,frag01)
                .add(R.id.fragment_layout,frag02)
                .show(frag01).hide(frag02).commit();
        //点击切换
        radio_group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
               FragmentTransaction transaction =  manager.beginTransaction();
               switch (checkedId){
                   case R.id.rd1:
                       transaction.show(frag01).hide(frag02);
                       break;
                   case R.id.rd2:
                       transaction.show(frag02).hide(frag01);
                       break;
               }
               transaction.commit();
            }
        });
    
    }
    

    }

    展开全文
  • framelayout页面切换

    2019-04-21 20:04:20
    framelayout页面切换,先继承FragmentActivity public class MainActivity extends FragmentActivity { private FrameLayout feame_layout; private RadioGroup radio_group; @Override protected void ...

    framelayout页面切换,先继承FragmentActivity

    public class MainActivity extends FragmentActivity {
    
    private FrameLayout feame_layout;
    private RadioGroup radio_group;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
    //初始化控件
    
        feame_layout = findViewById(R.id.feame_layout);
        radio_group = findViewById(R.id.radio_group);
    
        radio_group.check(radio_group.getChildAt(0).getId());
    
    //先写两个Fragment然后弄到这里来
    
        final FragmentOneActivity  oneActivity = new FragmentOneActivity();
        final FragmentTwoActivity twoActivity = new FragmentTwoActivity();
    
        final FragmentManager manager = getSupportFragmentManager();
        manager.beginTransaction()
                .add(R.id.feame_layout,oneActivity)
                .add(R.id.feame_layout , twoActivity)
                .commit();
                
    //默认第一个页面展示,第二个页面隐藏
    
        manager.beginTransaction().hide(twoActivity).show(oneActivity).commit();
        
    //加点击事件
    
        radio_group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId){
                    case R.id.radio0:
                        manager.beginTransaction().hide(twoActivity).show(oneActivity).commit();
                        break;
                        case R.id.radio1:
                        manager.beginTransaction().hide(oneActivity).show(twoActivity).commit();
                        break;
                }
            }
        });
    }
    }
    
    展开全文
  • FrameLayout布局切换

    2018-12-20 20:40:23
    android:layout_weight="1"></FrameLayout> 2,MainActivity public class MainActivity extends FragmentActivity { private FrameLayout fram; private RadioGroup rg; private Fra1 fra1=new Fra1(); ...

    1,activity_main

    <RadioGroup
        android:id="@+id/rg"
        android:layout_width="100dp"
        android:layout_height="wrap_content" >
    
        <RadioButton
            android:id="@+id/radioButton1"
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:layout_weight="1"
            android:text="商家1"
            android:button="@null"
            android:gravity="center"
            />
    
        <RadioButton
            android:id="@+id/radioButton2"
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:layout_weight="1"
            android:text="商家2"
            android:button="@null"
            android:gravity="center"/>
    
        <RadioButton
            android:id="@+id/radioButton3"
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:layout_weight="1"
            android:text="商家3"
            android:button="@null"
            android:gravity="center"/>
    </RadioGroup>
    
    <FrameLayout
        android:id="@+id/fram"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="1"></FrameLayout>
    

    2,MainActivity

    public class MainActivity extends FragmentActivity {
    
        private FrameLayout fram;
        private RadioGroup rg;
        private Fra1 fra1=new Fra1();
        private Fra2 fra2=new Fra2();
        private Fra3 fra3=new Fra3();
        private FragmentManager manager;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            fram = findViewById(R.id.fram);
            rg = findViewById(R.id.rg);
            manager = getSupportFragmentManager();
    
    
            manager.beginTransaction().replace(R.id.fram,fra1).commit();
    
            rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(RadioGroup group, int checkedId) {
                    FragmentTransaction tran = manager.beginTransaction();
                    switch (checkedId)
                    {
                        case R.id.radioButton1:
                            tran.replace(R.id.fram,fra1);
    
                            break;
                        case R.id.radioButton2:
                            tran.replace(R.id.fram,fra2);
    
                            break;
                        case R.id.radioButton3:
                            tran.replace(R.id.fram,fra3);
                            break;
                    }
    
                    tran.commit();
                }
            });
    
    
        }
    }
    
    展开全文
  • FrameLayout按钮切换页面

    千次阅读 2018-12-20 20:13:20
    一、xml <FrameLayout android:id="@+id/pager" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:text="TextView...

    一、xml

    <FrameLayout
            android:id="@+id/pager"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:text="TextView" />
    
        <RadioGroup
            android:id="@+id/radiogroup"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
    
            <RadioButton
                android:id="@+id/radioButton"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:button="@null"
                android:gravity="center"
                android:drawableTop="@drawable/sul_button1"
                android:text="@string/a" />
    
            <RadioButton
                android:id="@+id/radioButton2"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:button="@null"
                android:gravity="center"
                android:drawableTop="@drawable/sul_button2"
                android:text="@string/b" />
    
            <RadioButton
                android:id="@+id/radioButton3"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:button="@null"
                android:gravity="center"
                android:drawableTop="@drawable/sul_button3"
                android:text="@string/c" />
        </RadioGroup>

    二、Activity

    public class Main2Activity extends AppCompatActivity {
    
        private FrameLayout pager;
        private RadioGroup group;
        private ArrayList<Fragment> list;
        private Fragment01 fragment01;
        private Fragment02 fragment02;
        private Fragment03 fragment03;
        private FragmentManager manager;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main2);
    
            //初始化
            pager = findViewById(R.id.pager);
            group = findViewById(R.id.radiogroup);
    
            //获取事物
            manager = getSupportFragmentManager();
            //开启事物
            FragmentTransaction transaction = manager.beginTransaction();
            //new新的界面
            fragment01 = new Fragment01();
            fragment02 = new Fragment02();
            fragment03 = new Fragment03();
            //事物添加
            transaction.add(R.id.pager,fragment01);
            transaction.add(R.id.pager,fragment02);
            transaction.add(R.id.pager,fragment03);
            //展示一个界面隐藏另外两个
            transaction.show(fragment01).hide(fragment02).hide(fragment03);
            //提交事物
            transaction.commit();
    
            //默认选中第一个界面
            group.check(group.getChildAt(0).getId());
    
            //点击界面
            group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(RadioGroup group, int checkedId) {
                    //开启事物
                    FragmentTransaction transaction1 = manager.beginTransaction();
                    //选择
                    switch (checkedId){
                        case R.id.radioButton:
                            //展示一个界面,隐藏另外两个界面
                            transaction1.show(fragment01).hide(fragment02).hide(fragment03);
                            break;
                        case R.id.radioButton2:
                            transaction1.show(fragment02).hide(fragment01).hide(fragment03);
                            break;
                        case R.id.radioButton3:
                            transaction1.show(fragment03).hide(fragment01).hide(fragment02);
                            break;
                    }
                    //提交事物
                    transaction1.commit();
                }
            });
        }
    }
    

     

    展开全文
  • FrameLayout+底部栏切换

    2015-11-18 21:42:55
    FrameLayout+底部栏切换,实现点击切换界面的效果
  • //点击按钮处理切换逻辑 group .setOnCheckedChangeListener( new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup radioGroup, int id) { //i 就是你点击的...
  • FrameLayout frameLayout; @BindView(R.id.rb_home) RadioButton rbHome; @BindView(R.id.rb_circle) RadioButton rbCircle; @BindView(R.id.rb_shoppingCart) RadioButton rbShoppingCart; @BindView(R.id....
  • viewpager+FrameLayout activity的切换

    千次阅读 2016-12-08 14:15:56
    今天写的是viewpager+FrameLayout ,activity的切换还有页标的显示与切换,就是下面有小圆点的,每切换一个页面就小圆点就会切换到相应的页标上面。 不多说了,直接上代码了! MainActivity import java
  • 昨天发现使用Google的BottomNavigationView重写了OnNavigationItemSelectedListener之后切换不了fragment在查询了半天资料无果后,发现了一种区别去viewpager的方法 在这里记录一下 使用fragment一般有两种方式 一...
  • //定义数据 ...private FrameLayout fram; private RadioGroup radio; private FragmentManager manager; private FragmentTransaction transaction; private YiFragment yiFragment; private Er...
  • FrameLayout是一种比较简单的布局。他的原理就是,整个界面就是一个空白区域,当有新元素要添加时就全部放在这个空白区域的左上角,一个个叠上去,有点类似于卡片一张叠一张的作用。这样后面放的元素全部直接覆盖在...
  • framelayout中fragment的切换

    千次阅读 2017-08-10 14:32:54
    我们在android开发中经常会用到fragment,例如侧拉栏的切换,viewPager的切换。 而我们切换fragment无非就两种方法: 1.replace(); 2.add(),hide(),show(); 两种发方法相比较而言,我更加...
  • Fragment+FrameLayout实现Tab切换

    千次阅读 2018-05-09 17:49:31
    底部切换效果已经很常见了,本文介绍其中的一种实现方法: FrameLayout+Fragment 本案例已上传至Github,你可以查看 完整源码 ,也可以下载 demo apk 体验一下 实现效果如下: Tab切换 Step1:...
  • 目前众多App主界面采取底部导航栏与Framelayout这种方法来实现页面分割,而不是可滑动的ViewPager(感觉主要是因为所有页面都滑动会导致用户体验不佳)。 而实现当前功能则主要有两种方法。 1.replace(); 2.add...
  • 例:MainActivity 主方法:public class MainActivity extends ... private FrameLayout fl_main; private RadioGroup group; private ArrayList&lt;Fragment&gt; fragments; private Fr...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 805
精华内容 322
关键字:

framelayout切换