Fragment碎片片段(ViewPage+Fragment实现大致微信的界面滑动)
来源:互联网 发布:软件需求变更申请表 编辑:程序博客网 时间:2024/06/06 18:16
Fragment用途:
可以把两个Activity同是放到一个Activity里面。
今天来分享下用Fragment和ViewPage大致实现一个微信的界面滑动
首先要写五个界面
第一个是界面ViewPage
<?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="match_parent" android:orientation="vertical" tools:context="com.example.jane0615_test.MainActivity"> <android.support.v4.view.ViewPager android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:id="@+id/vp"> </android.support.v4.view.ViewPager> <RadioGroup android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/rg"> <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="微信" android:drawableTop="@drawable/selector_1" android:button="@null" android:id="@+id/rb_1"/> <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="通讯录" android:drawableTop="@drawable/selector_1" android:button="@null" android:id="@+id/rb_2"/> <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="发现" android:drawableTop="@drawable/selector_1" android:button="@null" android:id="@+id/rb_3"/> <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="我" android:drawableTop="@drawable/selector_1" android:button="@null" android:id="@+id/rb_4"/> </RadioGroup></LinearLayout>另外是四个分别是仿照微信里的三个界面微信、通讯录、发现、我
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"><TextView android:layout_width="match_parent" android:layout_height="match_parent" android:text="微信" android:background="#FFBBD3F4"/></LinearLayout>
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"><TextView android:layout_width="match_parent" android:layout_height="match_parent" android:text="通讯录" android:background="#33ff00ff"/></LinearLayout>
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="match_parent" android:layout_height="match_parent" android:text="发现" android:background="#66ffff00"/></LinearLayout>
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"><TextView android:layout_width="match_parent" android:layout_height="match_parent" android:text="我" android:background="#66ff0000"/></LinearLayout>
再写个selector文件,传两张图片
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_checked="false" android:drawable="@drawable/angle_end"></item> <item android:state_checked="true" android:drawable="@drawable/angle_start"></item></selector>
上面都是界面,
package com.example.jane0615_test;import android.support.v4.app.Fragment;import android.os.Bundle;import android.support.annotation.Nullable;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;/** * Created by Administrator on 2017/6/15 0015. */public class WeiXinFragment extends Fragment{ @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment_weixin,null); }}
package com.example.jane0615_test;import android.support.v4.app.Fragment;import android.os.Bundle;import android.support.annotation.Nullable;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;/** * Created by Administrator on 2017/6/15 0015. */public class ContactFragment extends Fragment { @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment_contact,null); }}
package com.example.jane0615_test;import android.support.v4.app.Fragment;import android.os.Bundle;import android.support.annotation.Nullable;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;/** * Created by Administrator on 2017/6/15 0015. */public class FindFragment extends Fragment { @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment_find,null); }}
package com.example.jane0615_test;import android.support.v4.app.Fragment;import android.os.Bundle;import android.support.annotation.Nullable;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;/** * Created by Administrator on 2017/6/15 0015. */public class MyFragment extends Fragment{ @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { return inflater.inflate(R.layout.fragment_my,null); }}
package com.example.jane0615_test;import android.support.annotation.IdRes;import android.support.v4.app.Fragment;import android.support.v4.app.FragmentManager;import android.support.v4.app.FragmentPagerAdapter;import android.support.v4.view.ViewPager;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.widget.RadioGroup;import java.util.ArrayList;import java.util.List;public class MainActivity extends AppCompatActivity { private List<Fragment> list=new ArrayList<>(); private ViewPager vp; private int[] images={R.id.rb_1,R.id.rb_2,R.id.rb_3,R.id.rb_4}; private RadioGroup rg; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); vp = (ViewPager) findViewById(R.id.vp); rg = (RadioGroup) findViewById(R.id.rg); WeiXinFragment weiXinFragment=new WeiXinFragment(); ContactFragment contactFragment=new ContactFragment(); FindFragment findFragment=new FindFragment(); MyFragment myFragment=new MyFragment(); list.add(weiXinFragment); list.add(contactFragment); list.add(findFragment); list.add(myFragment); vp.setCurrentItem(0); rg.check(images[0]);// rg.setOnCheck; vp.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Override public void onPageSelected(int position) { } @Override public void onPageScrollStateChanged(int state) { if(state==2){ rg.check(images[vp.getCurrentItem()]); } } }); vp.setAdapter(new My(getSupportFragmentManager())); } class My extends FragmentPagerAdapter{ public My(FragmentManager fm) { super(fm); } @Override public Fragment getItem(int position) { return null; } @Override public int getCount() { return 0; } } }
阅读全文
0 0
- Fragment碎片片段(ViewPage+Fragment实现大致微信的界面滑动)
- Android-Fragment碎片-片段制作微信的页面滑动
- Android-Fragment碎片-片段制作微信的页面滑动
- Viewpage和Fragment实现页面切换,微信界面
- 使用ViewPage+Fragment模仿微信界面
- 记录ViewPage+Fragment嵌套ViewPage+Fragment滑动时内部嵌套卡顿的问题和实现Fragment的懒加载
- Android-Fragment碎片-片段
- Fragment碎片-片段
- viewpage+fragment+下划线滑动
- ViewPage+Fragment 滑动+点击
- ViewPage+Fragment 滑动+点击
- 【Android UI】Fragment+ViewPage实现滑动
- viewpage+fragment的简单实现
- Android 中Fragment+ViewPage+Tablayout 实现 左右滑动(新学的方法)
- Android使用Fragment嵌套Fragment的方式实现界面滑动
- 用ViewPager+Fragment(碎片)实现滑动效果
- Android ViewPager+Fragment(碎片)实现页面滑动
- ViewPager+Fragment实现界面滑动
- MyEclipse使用Maven创建web项目+搭建SSM框架教
- Lua 字符串实践 -- 过滤词库算法
- 队列和循环队列的实现
- 电脑重装系统(win7)
- 设计模式之策略模式
- Fragment碎片片段(ViewPage+Fragment实现大致微信的界面滑动)
- Ubuntu必备软件
- 写了个静态的网页-模仿网易云
- JS模块化编程
- Cannot remove entries from nonexistent file /usr/local/bin/anaconda2/lib/python2.7/site-packages/eas
- 数据库范式
- Java学习之Iterator(迭代器)的一般用法 (转)
- 使用Mybatis生成工具自动生成实体类和对应的mapper映射文件以及接口文件
- poll函数