Android SlidingMenu 仿网易新闻客户端布局

简介:

前面两篇文章中的SlidingMenu都出现在左侧,今天来模仿一下网易新闻客户端左右两边都有SlidingMenu的效果,以下是网易新闻客户端效果:

 

 

 

 

 

 

 

不扯闲话了,直接进入正题吧

 

frame_content.xml

 

[html]  view plain copy 在CODE上查看代码片 派生到我的代码片
 
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:id="@+id/content"  
  4.     android:layout_width="match_parent"  
  5.     android:layout_height="match_parent" />  


 

frame_left_menu.xml

 

[html]  view plain copy 在CODE上查看代码片 派生到我的代码片
 
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:id="@+id/left_menu"  
  4.     android:layout_width="match_parent"  
  5.     android:layout_height="match_parent" />  

 

frame_right_menu.xml

 

[html]  view plain copy 在CODE上查看代码片 派生到我的代码片
 
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:id="@+id/right_menu"  
  4.     android:layout_width="match_parent"  
  5.     android:layout_height="match_parent" />  


 

在 主Activity 初始化 SlidingMenu

 

[java]  view plain copy 在CODE上查看代码片 派生到我的代码片
 
  1. package com.example.slidingmenuwangyi;  
  2.   
  3. import android.annotation.SuppressLint;  
  4. import android.os.Bundle;  
  5. import android.support.v4.app.Fragment;  
  6. import android.support.v4.app.FragmentManager;  
  7. import android.support.v4.app.FragmentTransaction;  
  8. import android.util.Log;  
  9. import android.view.Menu;  
  10. import android.view.MenuItem;  
  11. import android.widget.Toast;  
  12.   
  13. import com.example.slidingmenuwangyi.fragment.CommunityFragment;  
  14. import com.example.slidingmenuwangyi.fragment.FindPeopleFragment;  
  15. import com.example.slidingmenuwangyi.fragment.HomeFragment;  
  16. import com.example.slidingmenuwangyi.fragment.MenuFragment;  
  17. import com.example.slidingmenuwangyi.fragment.MenuFragment.SLMenuListOnItemClickListener;  
  18. import com.example.slidingmenuwangyi.fragment.PagesFragment;  
  19. import com.example.slidingmenuwangyi.fragment.PhotosFragment;  
  20. import com.example.slidingmenuwangyi.fragment.RightMenuFragment;  
  21. import com.example.slidingmenuwangyi.fragment.WhatsHotFragment;  
  22. import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;  
  23. import com.jeremyfeinstein.slidingmenu.lib.app.SlidingFragmentActivity;  
  24.   
  25. public class MainActivity extends SlidingFragmentActivity implements SLMenuListOnItemClickListener{  
  26.       
  27.     private SlidingMenu mSlidingMenu;  
  28.       
  29.     @SuppressLint("NewApi")  
  30.     @Override  
  31.     public void onCreate(Bundle savedInstanceState) {  
  32.         super.onCreate(savedInstanceState);  
  33.           
  34.         setTitle("Home");  
  35. //      setTitle(R.string.sliding_title);  
  36.         setContentView(R.layout.frame_content);  
  37.   
  38.         //set the Behind View  
  39.         setBehindContentView(R.layout.frame_left_menu);  
  40.           
  41.         // customize the SlidingMenu  
  42.         mSlidingMenu = getSlidingMenu();  
  43.         mSlidingMenu.setMode(SlidingMenu.LEFT_RIGHT);//设置左右都可以划出SlidingMenu菜单  
  44.         mSlidingMenu.setSecondaryMenu(R.layout.frame_right_menu);   //设置右侧菜单的布局文件  
  45.         mSlidingMenu.setSecondaryShadowDrawable(R.drawable.drawer_shadow);  
  46.           
  47. //      mSlidingMenu.setShadowWidth(5);  
  48. //      mSlidingMenu.setBehindOffset(100);  
  49.         mSlidingMenu.setShadowDrawable(R.drawable.drawer_shadow);//设置阴影图片  
  50.         mSlidingMenu.setShadowWidthRes(R.dimen.shadow_width); //设置阴影图片的宽度  
  51.         mSlidingMenu.setBehindOffsetRes(R.dimen.slidingmenu_offset); //SlidingMenu划出时主页面显示的剩余宽度  
  52.         mSlidingMenu.setFadeDegree(0.35f);  
  53.         //设置SlidingMenu 的手势模式  
  54.         //TOUCHMODE_FULLSCREEN 全屏模式,在整个content页面中,滑动,可以打开SlidingMenu  
  55.         //TOUCHMODE_MARGIN 边缘模式,在content页面中,如果想打开SlidingMenu,你需要在屏幕边缘滑动才可以打开SlidingMenu  
  56.         //TOUCHMODE_NONE 不能通过手势打开SlidingMenu  
  57.         mSlidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);  
  58.           
  59.         //设置 SlidingMenu 内容  
  60.         FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();  
  61.         fragmentTransaction.replace(R.id.left_menu, new MenuFragment());  
  62.         fragmentTransaction.replace(R.id.right_menu, new RightMenuFragment());  
  63.         fragmentTransaction.replace(R.id.content, new HomeFragment());  
  64.           
  65.         fragmentTransaction.commit();  
  66.           
  67.         //使用左上方icon可点,这样在onOptionsItemSelected里面才可以监听到R.id.home  
  68.         getActionBar().setDisplayHomeAsUpEnabled(true);  
  69. //        getActionBar().setLogo(R.drawable.ic_logo);  
  70.     }  
  71.   
  72.     @Override  
  73.     public boolean onCreateOptionsMenu(Menu menu) {  
  74.         // Inflate the menu; this adds items to the action bar if it is present.  
  75.         getMenuInflater().inflate(R.menu.main, menu);  
  76.         return true;  
  77.     }  
  78.       
  79.     @Override  
  80.     public boolean onOptionsItemSelected(MenuItem item) {  
  81.         switch (item.getItemId()) {  
  82.         case android.R.id.home:  
  83.               
  84.             toggle(); //动态判断自动关闭或开启SlidingMenu  
  85. //          getSlidingMenu().showMenu();//显示SlidingMenu  
  86. //          getSlidingMenu().showContent();//显示内容  
  87.             return true;  
  88.         case R.id.action_refresh:  
  89.               
  90.             Toast.makeText(getApplicationContext(), R.string.refresh, Toast.LENGTH_SHORT).show();  
  91.               
  92.             return true;  
  93.         case R.id.action_person:  
  94.               
  95.             if(mSlidingMenu.isSecondaryMenuShowing()){  
  96.                 mSlidingMenu.showContent();  
  97.             }else{  
  98.                 mSlidingMenu.showSecondaryMenu();  
  99.             }  
  100.             return true;  
  101.         default:  
  102.             return super.onOptionsItemSelected(item);  
  103.         }  
  104.           
  105.     }  
  106.   
  107.     @SuppressLint("NewApi")  
  108.     @Override  
  109.     public void selectItem(int position, String title) {  
  110.         // update the main content by replacing fragments    
  111.         Fragment fragment = null;    
  112.         switch (position) {    
  113.         case 0:    
  114.             fragment = new HomeFragment();    
  115.             break;    
  116.         case 1:    
  117.             fragment = new FindPeopleFragment();    
  118.             break;    
  119.         case 2:    
  120.             fragment = new PhotosFragment();    
  121.             break;    
  122.         case 3:    
  123.             fragment = new CommunityFragment();    
  124.             break;    
  125.         case 4:    
  126.             fragment = new PagesFragment();    
  127.             break;    
  128.         case 5:    
  129.             fragment = new WhatsHotFragment();    
  130.             break;    
  131.         default:    
  132.             break;    
  133.         }    
  134.         
  135.         if (fragment != null) {    
  136.             FragmentManager fragmentManager = getSupportFragmentManager();  
  137.             fragmentManager.beginTransaction()    
  138.                     .replace(R.id.content, fragment).commit();    
  139.             // update selected item and title, then close the drawer    
  140.             setTitle(title);  
  141.             mSlidingMenu.showContent();  
  142.         } else {    
  143.             // error in creating fragment    
  144.             Log.e("MainActivity""Error in creating fragment");    
  145.         }    
  146.     }  
  147. }  


 

左边SlidingMenu Fragment

 

[java]  view plain copy 在CODE上查看代码片 派生到我的代码片
 
  1. package com.example.slidingmenuwangyi.fragment;  
  2.   
  3. import java.util.ArrayList;  
  4.   
  5. import android.app.Activity;  
  6. import android.content.res.TypedArray;  
  7. import android.os.Bundle;  
  8. import android.support.v4.app.Fragment;  
  9. import android.view.LayoutInflater;  
  10. import android.view.View;  
  11. import android.view.ViewGroup;  
  12. import android.widget.AdapterView;  
  13. import android.widget.AdapterView.OnItemClickListener;  
  14. import android.widget.ListView;  
  15.   
  16. import com.example.slidingmenuwangyi.R;  
  17. import com.example.slidingmenuwangyi.adapter.NavDrawerListAdapter;  
  18. import com.example.slidingmenuwangyi.entity.NavDrawerItem;  
  19.   
  20. public class MenuFragment extends Fragment implements OnItemClickListener {  
  21.   
  22.     private ListView mDrawerList;  
  23.     private String[] mNavMenuTitles;  
  24.     private TypedArray mNavMenuIconsTypeArray;  
  25.     private ArrayList<NavDrawerItem> mNavDrawerItems;  
  26.     private NavDrawerListAdapter mAdapter;  
  27.     private SLMenuListOnItemClickListener mCallback;  
  28.     private int selected = -1;  
  29.   
  30.     @Override  
  31.     public void onAttach(Activity activity) {  
  32.         try {  
  33.             mCallback = (SLMenuListOnItemClickListener) activity;  
  34.         } catch (ClassCastException e) {  
  35.             throw new ClassCastException(activity.toString()  
  36.                     + " must implement OnResolveTelsCompletedListener");  
  37.         }  
  38.         super.onAttach(activity);  
  39.     }  
  40.       
  41.     @Override  
  42.     public void onCreate(Bundle savedInstanceState) {  
  43.         // TODO Auto-generated method stub  
  44.         super.onCreate(savedInstanceState);  
  45.     }  
  46.       
  47.     @Override  
  48.     public View onCreateView(LayoutInflater inflater, ViewGroup container,  
  49.             Bundle savedInstanceState) {  
  50.           
  51.         View rootView = inflater.inflate(R.layout.fragment_menu, null);  
  52.           
  53.         findView(rootView);  
  54.           
  55.         return rootView;  
  56.     }  
  57.   
  58.     private void findView(View rootView) {  
  59.           
  60.         mDrawerList = (ListView) rootView.findViewById(R.id.left_menu);    
  61.           
  62.         mNavMenuTitles = getResources().getStringArray(R.array.nav_drawer_items);    
  63.         // nav drawer icons from resources    
  64.         mNavMenuIconsTypeArray = getResources()    
  65.                     .obtainTypedArray(R.array.nav_drawer_icons);    
  66.                 
  67.         mNavDrawerItems = new ArrayList<NavDrawerItem>();    
  68.     
  69.         // adding nav drawer items to array    
  70.         // Home    
  71.         mNavDrawerItems.add(new NavDrawerItem(mNavMenuTitles[0], mNavMenuIconsTypeArray    
  72.                 .getResourceId(0, -1)));    
  73.         // Find People    
  74.         mNavDrawerItems.add(new NavDrawerItem(mNavMenuTitles[1], mNavMenuIconsTypeArray    
  75.                 .getResourceId(1, -1)));    
  76.         // Photos    
  77.         mNavDrawerItems.add(new NavDrawerItem(mNavMenuTitles[2], mNavMenuIconsTypeArray    
  78.                 .getResourceId(2, -1)));    
  79.         // Communities, Will add a counter here    
  80.         mNavDrawerItems.add(new NavDrawerItem(mNavMenuTitles[3], mNavMenuIconsTypeArray    
  81.                 .getResourceId(3, -1), true"22"));    
  82.         // Pages    
  83.         mNavDrawerItems.add(new NavDrawerItem(mNavMenuTitles[4], mNavMenuIconsTypeArray    
  84.                 .getResourceId(4, -1)));    
  85.         // What's hot, We will add a counter here    
  86.         mNavDrawerItems.add(new NavDrawerItem(mNavMenuTitles[5], mNavMenuIconsTypeArray    
  87.                 .getResourceId(5, -1), true"50+"));    
  88.     
  89.         // Recycle the typed array    
  90.         mNavMenuIconsTypeArray.recycle();    
  91.             
  92.         // setting the nav drawer list adapter    
  93.         mAdapter = new NavDrawerListAdapter(getActivity(),    
  94.                         mNavDrawerItems);    
  95.         mDrawerList.setAdapter(mAdapter);    
  96.         mDrawerList.setOnItemClickListener(this);    
  97.           
  98.         if(selected!=-1){  
  99.             mDrawerList.setItemChecked(selected, true);    
  100.             mDrawerList.setSelection(selected);    
  101.         }else{  
  102.             mDrawerList.setItemChecked(0true);    
  103.             mDrawerList.setSelection(0);    
  104.         }  
  105.     }  
  106.   
  107.     @Override  
  108.     public void onItemClick(AdapterView<?> parent, View view, int position,  
  109.             long id) {  
  110.           
  111.         // update selected item and title, then close the drawer    
  112.         mDrawerList.setItemChecked(position, true);    
  113.         mDrawerList.setSelection(position);    
  114.           
  115.         if(mCallback!=null){  
  116.             mCallback.selectItem(position, mNavMenuTitles[position]);  
  117.         }  
  118.         selected = position;  
  119.     }  
  120.   
  121.     /** 
  122.      * 左侧菜单 点击回调接口 
  123.      * @author FX_SKY 
  124.      * 
  125.      */  
  126.     public interface SLMenuListOnItemClickListener{  
  127.           
  128.         public void selectItem(int position,String title);  
  129.     }  
  130. }  


 

MenuFragment 布局文件fragment_menu.xml

 

[html]  view plain copy 在CODE上查看代码片 派生到我的代码片
 
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent" >  
  5.       
  6.     <ListView    
  7.         android:id="@+id/left_menu"    
  8.         android:layout_width="match_parent"    
  9.         android:layout_height="match_parent"    
  10.         android:layout_gravity="start"    
  11.         android:choiceMode="singleChoice"    
  12.         android:divider="@android:color/transparent"    
  13.         android:dividerHeight="0dp"    
  14.         android:background="#111"/>    
  15.   
  16. </RelativeLayout>  


 

右边SlidingMenu Fragment

 

[java]  view plain copy 在CODE上查看代码片 派生到我的代码片
 
  1. package com.example.slidingmenuwangyi.fragment;  
  2.   
  3. import android.app.Activity;  
  4. import android.os.Bundle;  
  5. import android.support.v4.app.Fragment;  
  6. import android.view.LayoutInflater;  
  7. import android.view.View;  
  8. import android.view.ViewGroup;  
  9.   
  10. import com.example.slidingmenuwangyi.R;  
  11.   
  12. public class RightMenuFragment extends Fragment{  
  13.   
  14.     @Override  
  15.     public void onAttach(Activity activity) {  
  16.           
  17.         super.onAttach(activity);  
  18.     }  
  19.       
  20.     @Override  
  21.     public void onCreate(Bundle savedInstanceState) {  
  22.         // TODO Auto-generated method stub  
  23.         super.onCreate(savedInstanceState);  
  24.     }  
  25.       
  26.     @Override  
  27.     public View onCreateView(LayoutInflater inflater, ViewGroup container,  
  28.             Bundle savedInstanceState) {  
  29.           
  30.         View rootView = inflater.inflate(R.layout.fragment_right_menu, null);  
  31.           
  32.         findView(rootView);  
  33.           
  34.         return rootView;  
  35.     }  
  36.   
  37.     private void findView(View rootView) {  
  38.           
  39.     }  
  40.   
  41. }  


 

RightMenuFragment 布局文件 fragment_right_menu.xml

 

[html]  view plain copy 在CODE上查看代码片 派生到我的代码片
 
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"   
  5.     android:orientation="vertical"  
  6.     android:background="#464646">  
  7.       
  8.     <!-- 顶部个人基本信息 -->  
  9.     <RelativeLayout   
  10.         android:layout_width="fill_parent"  
  11.         android:layout_height="70dip">  
  12.         <ImageView   
  13.             android:id="@+id/right_permsg_center_img_usericon"  
  14.             android:layout_width="60dip"  
  15.             android:layout_height="60dip"  
  16.             android:layout_marginLeft="5dip"  
  17.             android:layout_marginTop="5dip"  
  18.             android:layout_marginBottom="5dip"  
  19.             android:src="@drawable/night_biz_pc_account_avatar_bg"  
  20.             android:scaleType="fitXY"/>  
  21.         <TextView   
  22.             android:id="@+id/right_permsg_center_tv_name"  
  23.             android:layout_width="wrap_content"  
  24.             android:layout_height="wrap_content"  
  25.             android:text="AABBV"  
  26.             android:layout_toRightOf="@id/right_permsg_center_img_usericon"  
  27.             android:layout_marginLeft="10dip"  
  28.             android:textColor="@color/whilte"  
  29.             android:textSize="15sp"  
  30.             android:layout_marginTop="13dip"/>  
  31.         <ImageView   
  32.             android:id="@+id/right_permsg_center_img_icon"  
  33.             android:layout_width="15dip"  
  34.             android:layout_height="15dip"  
  35.             android:scaleType="fitXY"  
  36.             android:layout_toRightOf="@id/right_permsg_center_img_usericon"  
  37.             android:layout_below="@id/right_permsg_center_tv_name"  
  38.             android:src="@drawable/biz_pc_main_money_icon"  
  39.             android:layout_alignLeft="@id/right_permsg_center_tv_name"/>  
  40.         <TextView   
  41.             android:id="@+id/right_permsg_center_tv_level"  
  42.             android:layout_width="wrap_content"  
  43.             android:layout_height="wrap_content"  
  44.             android:layout_below="@id/right_permsg_center_tv_name"  
  45.             android:layout_toRightOf="@id/right_permsg_center_img_icon"  
  46.             android:text="科长"  
  47.             android:textColor="@color/whilte"  
  48.             android:layout_marginLeft="5dip"  
  49.             android:textSize="10sp"  
  50.             android:layout_alignBaseline="@id/right_permsg_center_img_icon"  
  51.             android:layout_marginTop="2dip"/>  
  52.         <ImageButton   
  53.             android:id="@+id/right_permsg_center_imgbtn_select"  
  54.             android:layout_width="30dip"  
  55.             android:layout_height="30dip"  
  56.             android:layout_alignParentRight="true"  
  57.             android:layout_marginRight="10dip"  
  58.             android:background="@drawable/app_recommend_arrow"  
  59.             android:layout_centerVertical="true"/>  
  60.     </RelativeLayout>  
  61.       
  62.     <!-- 中间三个button  我的跟帖,我的收藏,消息推送 -->  
  63.     <LinearLayout   
  64.         android:layout_width="fill_parent"  
  65.         android:layout_height="wrap_content"  
  66.         android:orientation="horizontal">  
  67.         <Button  
  68.             android:id="@+id/right_permsg_center_btn_thread"  
  69.             android:layout_width="wrap_content"  
  70.             android:layout_height="wrap_content"  
  71.             android:text="我的跟帖"  
  72.             android:drawableTop="@drawable/biz_pc_go_tie"  
  73.             android:background="#00000000"  
  74.             android:textColor="@color/whilte"  
  75.             android:layout_weight="1"  
  76.              />  
  77.         <Button  
  78.             android:id="@+id/right_permsg_center_btn_collect"  
  79.             android:layout_width="wrap_content"  
  80.             android:layout_height="wrap_content"  
  81.             android:text="我的收藏"  
  82.             android:drawableTop="@drawable/biz_pc_go_favor"  
  83.             android:background="#00000000"  
  84.             android:textColor="@color/whilte"  
  85.             android:layout_weight="1"  
  86.             />  
  87.         <Button  
  88.              
  89.             android:id="@+id/right_permsg_center_btn_msgpush"  
  90.             android:layout_width="wrap_content"  
  91.             android:layout_height="wrap_content"  
  92.             android:text="消息推送"  
  93.             android:drawableTop="@drawable/biz_pc_go_msg"  
  94.             android:background="#00000000"  
  95.             android:textColor="@color/whilte"  
  96.             android:layout_weight="1"  
  97.             />        
  98.     </LinearLayout>  
  99.       
  100.   
  101. </LinearLayout>  


 

主Fragment  HomeFragment

 

[java]  view plain copy 在CODE上查看代码片 派生到我的代码片
 
  1. package com.example.slidingmenuwangyi.fragment;  
  2.   
  3. import java.util.ArrayList;  
  4. import java.util.List;  
  5.   
  6. import android.os.Bundle;  
  7. import android.support.v4.app.Fragment;  
  8. import android.support.v4.view.PagerTabStrip;  
  9. import android.support.v4.view.ViewPager;  
  10. import android.view.LayoutInflater;  
  11. import android.view.View;  
  12. import android.view.ViewGroup;  
  13.   
  14. import com.example.slidingmenuwangyi.R;  
  15. import com.example.slidingmenuwangyi.adapter.ContentFragmentPagerAdapter;  
  16. import com.example.slidingmenuwangyi.entity.ContentBean;  
  17.   
  18. public class HomeFragment extends Fragment {  
  19.       
  20.     private ViewPager mViewPager;  
  21.     private static final String[] titles = {"One","Two","Three","Four","Five"};  
  22.     private List<ContentBean> list = new ArrayList<ContentBean>();  
  23.     private ContentFragmentPagerAdapter mAdapter;  
  24.       
  25.     public HomeFragment(){}  
  26.       
  27.     @Override  
  28.     public View onCreateView(LayoutInflater inflater, ViewGroup container,  
  29.             Bundle savedInstanceState) {  
  30.    
  31.         View rootView = inflater.inflate(R.layout.fragment_home, container, false);  
  32.           
  33.         initData();  
  34.         findView(rootView);  
  35.           
  36.         return rootView;  
  37.     }  
  38.   
  39.     private void initData() {  
  40.           
  41.         for(int i=0;i<titles.length;i++){  
  42.               
  43.             ContentBean cb = new ContentBean();  
  44.             cb.setTitle(titles[i]);  
  45.             cb.setContent(titles[i]+"_"+(i+1));  
  46.               
  47.             list.add(cb);  
  48.         }  
  49.     }  
  50.   
  51.     private void findView(View rootView) {  
  52.           
  53.         mViewPager = (ViewPager) rootView.findViewById(R.id.mViewPager);  
  54.           
  55.         PagerTabStrip mPagerTabStrip = (PagerTabStrip) rootView.findViewById(R.id.mPagerTabStrip);  
  56.         mPagerTabStrip.setTabIndicatorColor(getResources().getColor(R.color.select_text_color));   
  57.           
  58.         mAdapter = new ContentFragmentPagerAdapter(getActivity().getSupportFragmentManager(),list);  
  59.         mViewPager.setAdapter(mAdapter);  
  60.     }  
  61.       
  62.     @Override  
  63.     public void onStart() {  
  64.           
  65.         if(mAdapter!=null){  
  66.             mAdapter.notifyDataSetChanged();  
  67.         }  
  68.           
  69.         super.onStart();  
  70.     }  
  71. }  


 

HomeFragment 布局文件 fragment_home.xml

 

[html]  view plain copy 在CODE上查看代码片 派生到我的代码片
 
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent" >  
  5.   
  6.     <android.support.v4.view.ViewPager  
  7.         android:id="@+id/mViewPager"  
  8.         android:layout_width="match_parent"  
  9.         android:layout_height="wrap_content" >  
  10.           
  11.         <android.support.v4.view.PagerTabStrip      
  12.             android:id="@+id/mPagerTabStrip"      
  13.             android:layout_width="wrap_content"      
  14.             android:layout_height="wrap_content"      
  15.             android:layout_gravity="top"/>      
  16.           
  17. <!--         <android.support.v4.view.PagerTitleStrip  
  18.             android:id="@+id/mPagerTitleStrip"  
  19.             android:layout_width="match_parent"  
  20.             android:layout_height="wrap_content"  
  21.             android:layout_gravity="top" /> -->  
  22.     </android.support.v4.view.ViewPager>  
  23.   
  24. </RelativeLayout>  


 

 

别的就不贴了,自己下载下来看吧

 

 

运行效果如下

 

 

 

 

 

 其它干货下载资源已放入微信公众号【一个码农的日常】

Demo下载地址:http://download.csdn.net/detail/fx_sky/6725171

原文:http://blog.csdn.net/gebitan505/article/details/20390325

本文转自欢醉博客园博客,原文链接http://www.cnblogs.com/zhangs1986/p/3654638.html如需转载请自行联系原作者


欢醉

相关文章
|
5月前
|
Linux Android开发 iOS开发
基于.Net开发的ChatGPT客户端,兼容Windows、IOS、安卓、MacOS、Linux
基于.Net开发的ChatGPT客户端,兼容Windows、IOS、安卓、MacOS、Linux
88 0
|
8月前
|
XML 前端开发 Android开发
Android XML 布局基础(四)内外边距(margin、padding)
Android XML 布局基础(四)内外边距(margin、padding)
169 0
|
4月前
|
XML JSON Java
Android App开发即时通信中通过SocketIO在客户端与服务端间传输文本和图片的讲解及实战(超详细 附源码)
Android App开发即时通信中通过SocketIO在客户端与服务端间传输文本和图片的讲解及实战(超详细 附源码)
66 0
|
4月前
|
Android开发
Android Studio入门之常用布局的讲解以及实战(附源码 超详细必看)(包括线性布局、权重布局、相对布局、网格布局、滚动视图 )
Android Studio入门之常用布局的讲解以及实战(附源码 超详细必看)(包括线性布局、权重布局、相对布局、网格布局、滚动视图 )
128 0
|
4月前
|
Android开发 容器
Android开发,学习LinearLayout布局
Android开发,学习LinearLayout布局
39 0
|
4月前
|
XML Java Android开发
Android Studio App开发之循环试图RecyclerView,布局管理器LayoutManager、动态更新循环视图讲解及实战(附源码)
Android Studio App开发之循环试图RecyclerView,布局管理器LayoutManager、动态更新循环视图讲解及实战(附源码)
39 0
|
4月前
|
XML Java Android开发
Android Studio App开发中工具栏Toolbar、溢出菜单OverflowMenu、标签布局TabLayout的讲解及实战(实现京东App的标签导航栏,附源码)
Android Studio App开发中工具栏Toolbar、溢出菜单OverflowMenu、标签布局TabLayout的讲解及实战(实现京东App的标签导航栏,附源码)
58 0
|
4月前
|
Android开发 容器
Android开发第二次课 布局方式
Android开发第二次课 布局方式
23 0
|
6月前
|
XML 前端开发 Android开发
android 前端常用布局文件升级总结(一)
android 前端常用布局文件升级总结(一)
|
7月前
|
缓存 Java API
[Android 毕业设计/课程设计] 小而美的新闻客户端 App
[Android 毕业设计/课程设计] 小而美的新闻客户端 App