首页 > 其他分享 >仿网易新闻页面效果

仿网易新闻页面效果

时间:2022-12-14 20:40:10浏览次数:33  
标签:网易 layout 效果 height content width android id 页面



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


frame_content.xml



[html] ​​ view plain​​ ​​co



  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​​ ​​cop



  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​​ ​​co



  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​​ ​​co



  1. package
  2.   
  3. import
  4. import
  5. import
  6. import
  7. import
  8. import
  9. import
  10. import
  11. import
  12.   
  13. import
  14. import
  15. import
  16. import
  17. import
  18. import
  19. import
  20. import
  21. import
  22. import
  23. import
  24.   
  25. public class MainActivity extends SlidingFragmentActivity implements
  26.       
  27. private
  28.       
  29. @SuppressLint("NewApi")  
  30. @Override
  31. public void
  32. super.onCreate(savedInstanceState);  
  33.           
  34. "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. //设置左右都可以划出SlidingMenu菜单
  44. //设置右侧菜单的布局文件
  45.         mSlidingMenu.setSecondaryShadowDrawable(R.drawable.drawer_shadow);  
  46.           
  47. //      mSlidingMenu.setShadowWidth(5);
  48. //      mSlidingMenu.setBehindOffset(100);
  49. //设置阴影图片
  50. //设置阴影图片的宽度
  51. //SlidingMenu划出时主页面显示的剩余宽度
  52. 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. new
  62. new
  63. new
  64.           
  65.         fragmentTransaction.commit();  
  66.           
  67. //使用左上方icon可点,这样在onOptionsItemSelected里面才可以监听到R.id.home
  68. true);  
  69. //        getActionBar().setLogo(R.drawable.ic_logo);
  70.     }  
  71.   
  72. @Override
  73. public boolean
  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
  81. switch
  82. case
  83.               
  84. //动态判断自动关闭或开启SlidingMenu
  85. //          getSlidingMenu().showMenu();//显示SlidingMenu
  86. //          getSlidingMenu().showContent();//显示内容
  87. return true;  
  88. case
  89.               
  90.             Toast.makeText(getApplicationContext(), R.string.refresh, Toast.LENGTH_SHORT).show();  
  91.               
  92. return true;  
  93. case
  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
  110. // update the main content by replacing fragments  
  111. null;    
  112. switch
  113. case 0:    
  114. new
  115. break;    
  116. case 1:    
  117. new
  118. break;    
  119. case 2:    
  120. new
  121. break;    
  122. case 3:    
  123. new
  124. break;    
  125. case 4:    
  126. new
  127. break;    
  128. case 5:    
  129. new
  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. "MainActivity", "Error in creating fragment");    
  145.         }    
  146.     }  
  147. }  




左边SlidingMenu Fragment


[java] ​​ view plain​​ ​​cop



  1. package
  2.   
  3. import
  4.   
  5. import
  6. import
  7. import
  8. import
  9. import
  10. import
  11. import
  12. import
  13. import
  14. import
  15.   
  16. import
  17. import
  18. import
  19.   
  20. public class MenuFragment extends Fragment implements
  21.   
  22. private
  23. private
  24. private
  25. private
  26. private
  27. private
  28. private int selected = -1;  
  29.   
  30. @Override
  31. public void
  32. try
  33.             mCallback = (SLMenuListOnItemClickListener) activity;  
  34. catch
  35. throw new
  36. " must implement OnResolveTelsCompletedListener");  
  37.         }  
  38. super.onAttach(activity);  
  39.     }  
  40.       
  41. @Override
  42. public void
  43. // TODO Auto-generated method stub
  44. super.onCreate(savedInstanceState);  
  45.     }  
  46.       
  47. @Override
  48. public
  49.             Bundle savedInstanceState) {  
  50.           
  51. null);  
  52.           
  53.         findView(rootView);  
  54.           
  55. return
  56.     }  
  57.   
  58. private void
  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. new
  68.     
  69. // adding nav drawer items to array  
  70. // Home  
  71. new NavDrawerItem(mNavMenuTitles[0], mNavMenuIconsTypeArray    
  72. 0, -1)));    
  73. // Find People  
  74. new NavDrawerItem(mNavMenuTitles[1], mNavMenuIconsTypeArray    
  75. 1, -1)));    
  76. // Photos  
  77. new NavDrawerItem(mNavMenuTitles[2], mNavMenuIconsTypeArray    
  78. 2, -1)));    
  79. // Communities, Will add a counter here  
  80. new NavDrawerItem(mNavMenuTitles[3], mNavMenuIconsTypeArray    
  81. 3, -1), true, "22"));    
  82. // Pages  
  83. new NavDrawerItem(mNavMenuTitles[4], mNavMenuIconsTypeArray    
  84. 4, -1)));    
  85. // What's hot, We will add a counter here  
  86. new NavDrawerItem(mNavMenuTitles[5], mNavMenuIconsTypeArray    
  87. 5, -1), true, "50+"));    
  88.     
  89. // Recycle the typed array  
  90.         mNavMenuIconsTypeArray.recycle();    
  91.             
  92. // setting the nav drawer list adapter  
  93. new
  94.                         mNavDrawerItems);    
  95.         mDrawerList.setAdapter(mAdapter);    
  96. this);    
  97.           
  98. if(selected!=-1){  
  99. true);    
  100.             mDrawerList.setSelection(selected);    
  101. else{  
  102. 0, true);    
  103. 0);    
  104.         }  
  105.     }  
  106.   
  107. @Override
  108. public void onItemClick(AdapterView<?> parent, View view, int
  109. long
  110.           
  111. // update selected item and title, then close the drawer  
  112. 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
  127.           
  128. public void selectItem(int
  129.     }  
  130. }  




MenuFragment 布局文件fragment_menu.xml


[html] ​​ view plain​​ ​​co



  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​​ ​​cop



  1. package
  2.   
  3. import
  4. import
  5. import
  6. import
  7. import
  8. import
  9.   
  10. import
  11.   
  12. public class RightMenuFragment extends
  13.   
  14. @Override
  15. public void
  16.           
  17. super.onAttach(activity);  
  18.     }  
  19.       
  20. @Override
  21. public void
  22. // TODO Auto-generated method stub
  23. super.onCreate(savedInstanceState);  
  24.     }  
  25.       
  26. @Override
  27. public
  28.             Bundle savedInstanceState) {  
  29.           
  30. null);  
  31.           
  32.         findView(rootView);  
  33.           
  34. return
  35.     }  
  36.   
  37. private void
  38.           
  39.     }  
  40.   
  41. }  




RightMenuFragment 布局文件 fragment_right_menu.xml



[html] ​​ view plain​​ ​​cop



  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​​ ​​cop



  1. package
  2.   
  3. import
  4. import
  5.   
  6. import
  7. import
  8. import
  9. import
  10. import
  11. import
  12. import
  13.   
  14. import
  15. import
  16. import
  17.   
  18. public class HomeFragment extends
  19.       
  20. private
  21. private static final String[] titles = {"One","Two","Three","Four","Five"};  
  22. private List<ContentBean> list = new
  23. private
  24.       
  25. public
  26.       
  27. @Override
  28. public
  29.             Bundle savedInstanceState) {  
  30.    
  31. false);  
  32.           
  33.         initData();  
  34.         findView(rootView);  
  35.           
  36. return
  37.     }  
  38.   
  39. private void
  40.           
  41. for(int i=0;i<titles.length;i++){  
  42.               
  43. new
  44.             cb.setTitle(titles[i]);  
  45. "_"+(i+1));  
  46.               
  47.             list.add(cb);  
  48.         }  
  49.     }  
  50.   
  51. private void
  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. new
  59.         mViewPager.setAdapter(mAdapter);  
  60.     }  
  61.       
  62. @Override
  63. public void
  64.           
  65. if(mAdapter!=null){  
  66.             mAdapter.notifyDataSetChanged();  
  67.         }  
  68.           
  69. super.onStart();  
  70.     }  
  71. }  




HomeFragment 布局文件 fragment_home.xml



[html] ​​ view plain​​ ​​co



  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>





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



标签:网易,layout,效果,height,content,width,android,id,页面
From: https://blog.51cto.com/u_13657808/5938323

相关文章