实验结果,可以实现通过左右活动来切换不同的界面。也可以通过点击不同的下方按钮来实现切换不同的界面。

自己也添加了相关的自己编写的小页面来展示相关的效果。主要的是对于碎片Fragment对于tap的相关应用。

具体的实验结果如下:

  1. private void initDatas() {
  2. mFragments = new ArrayList<>();
  3. //将四个Fragment加入集合中
  4. mFragments.add(new WeixinFragment());
  5. mFragments.add(new FrdFragment());
  6. mFragments.add(new AddressFragment());
  7. mFragments.add(new SettingFragment());
  8.  
  9. //初始化适配器
  10. mAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
  11. @Override
  12. public Fragment getItem(int position) {//从集合中获取对应位置的Fragment
  13. return mFragments.get(position);
  14. }
  15.  
  16. @Override
  17. public int getCount() {//获取集合中Fragment的总数
  18. return mFragments.size();
  19. }
  20.  
  21. };
  22. //不要忘记设置ViewPager的适配器
  23. mViewPager.setAdapter(mAdapter);
  24. //设置ViewPager的切换监听
  25. mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
  26. @Override
  27. //页面滚动事件
  28. public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
  29.  
  30. }
  31.  
  32. //页面选中事件
  33. @Override
  34. public void onPageSelected(int position) {
  35. //设置position对应的集合中的Fragment
  36. mViewPager.setCurrentItem(position);
  37. resetImgs();
  38. selectTab(position);
  39. }
  40.  
  41. @Override
  42. //页面滚动状态改变事件
  43. public void onPageScrollStateChanged(int state) {
  44.  
  45. }
  46. });
  47. }
  1. 这是对于此工程的主要代码的应用。就是对于Adapter的相关应用

在默认情况下,调用 PagerAdapter#notifyDataSetChanged() 并不会刷新已经存在的页面排序。需要我们重写 PagerAdapter#getItemPosition() 方法。该方法返回刷新后已经存在 fragment 的新位置。并且已经预定义好了两个常量 POSITION_NONE 和 POSITION_UNCHANGED,分别表示原先存在的 fragment 现在已经不在列表中了和原先存在的 fragment 刷新后位置没有发生改变。示例:

  1. @Override
  2. public int getItemPosition(Object object) {
  3. Fragment f = (Fragment) object;
  4. long id = f.getArguments().getLong("id");
  5. int index = indexOfId(id);
  6. return index == -1 ? POSITION_NONE : index;
  7. }
 

这里传入的 object 参数是 PagerAdaper#instantiateItem() 方法的返回值,在 FragmentPagerAdapter 中实际上是我们在 FragmentPagerAdapter#getItem() 中返回的

  1. @Override
  2. public Object instantiateItem(ViewGroup container, int position) {
  3. if (mCurTransaction == null) {
  4. mCurTransaction = mFragmentManager.beginTransaction();
  5. }
  6.  
  7. final long itemId = getItemId(position);
  8.  
  9. // Do we already have this fragment?
  10. String name = makeFragmentName(container.getId(), itemId);
  11. Fragment fragment = mFragmentManager.findFragmentByTag(name);
  12. if (fragment != null) {
  13. if (DEBUG) Log.v(TAG, "Attaching item #" + itemId + ": f=" + fragment);
  14. mCurTransaction.attach(fragment);
  15. } else {
  16. fragment = getItem(position);
  17. if (DEBUG) Log.v(TAG, "Adding item #" + itemId + ": f=" + fragment);
  18. mCurTransaction.add(container.getId(), fragment,
  19. makeFragmentName(container.getId(), itemId));
  20. }
  21. if (fragment != mCurrentPrimaryItem) {
  22. fragment.setMenuVisibility(false);
  23. fragment.setUserVisibleHint(false);
  24. }
  25.  
  26. return fragment;
  27. }

因为一般情况下,我们会把数据通过 Fragment#setArguments() 传递给 fragment 实例,所以就先从实例对象中获取到 fragment 的相关信息,然后确定 fragment 在新列表中的位置返回即可。这样,在我们调用 PagerAdapter#notifyDataSetChange() 之后,就会根据这个值调整已有的 fragment 的顺序并且创建新的还不存在的 fragment。假如该方法直接返回 POSITION_NONE,那么将会导致所有的 fragment 重建,在 fragment 创建开销比较大时,就会造成性能上的瓶颈。
如上重写了 getItemPosition() 了之后会发现当页面多了之后就出现了 bug。这是因为在 PagerAdapter 中默认使用 position 来唯一标识 fragment,在页面多之后就需要重建和销毁 fragment,而怎么找到需要销毁和重建的 fragment 呢,就是通过 position。

本次实验的实验结果如下:这就是产生的页面(通过点击下表或者是左右滑动都可以实现页面的跳转)

下面是主要的程序代码:

MainActivity.java

  1. package com.example.wenandroidcheck11;
  2.  
  3. import android.os.Bundle;
  4. import android.view.View;
  5. import android.view.View.OnClickListener;
  6. import android.view.Window;
  7. import android.widget.ImageButton;
  8. import android.widget.LinearLayout;
  9. import java.util.ArrayList;
  10. import java.util.List;
  11. import androidx.fragment.app.Fragment;
  12. import androidx.fragment.app.FragmentActivity;
  13. import androidx.fragment.app.FragmentPagerAdapter;
  14. import androidx.viewpager.widget.ViewPager;
  15.  
  16. public class MainActivity extends FragmentActivity implements OnClickListener {
  17. //声明ViewPager
  18. private ViewPager mViewPager;
  19. //适配器
  20. private FragmentPagerAdapter mAdapter;
  21. //装载Fragment的集合
  22. private List<Fragment> mFragments;
  23.  
  24. //四个Tab对应的布局
  25. private LinearLayout mTabWeixin;
  26. private LinearLayout mTabFrd;
  27. private LinearLayout mTabAddress;
  28. private LinearLayout mTabSetting;
  29.  
  30. //四个Tab对应的ImageButton
  31. private ImageButton mImgWeixin;
  32. private ImageButton mImgFrd;
  33. private ImageButton mImgAddress;
  34. private ImageButton mImgSetting;
  35.  
  36. @Override
  37. protected void onCreate(Bundle savedInstanceState) {
  38. super.onCreate(savedInstanceState);
  39. requestWindowFeature(Window.FEATURE_NO_TITLE);
  40. setContentView(R.layout.activity_main);
  41. initViews();//初始化控件
  42. initEvents();//初始化事件
  43. initDatas();//初始化数据
  44. }
  45.  
  46. private void initDatas() {
  47. mFragments = new ArrayList<>();
  48. //将四个Fragment加入集合中
  49. mFragments.add(new WeixinFragment());
  50. mFragments.add(new FrdFragment());
  51. mFragments.add(new AddressFragment());
  52. mFragments.add(new SettingFragment());
  53.  
  54. //初始化适配器
  55. mAdapter = new FragmentPagerAdapter(getSupportFragmentManager()) {
  56. @Override
  57. public Fragment getItem(int position) {//从集合中获取对应位置的Fragment
  58. return mFragments.get(position);
  59. }
  60.  
  61. @Override
  62. public int getCount() {//获取集合中Fragment的总数
  63. return mFragments.size();
  64. }
  65.  
  66. };
  67. //不要忘记设置ViewPager的适配器
  68. mViewPager.setAdapter(mAdapter);
  69. //设置ViewPager的切换监听
  70. mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
  71. @Override
  72. //页面滚动事件
  73. public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
  74.  
  75. }
  76.  
  77. //页面选中事件
  78. @Override
  79. public void onPageSelected(int position) {
  80. //设置position对应的集合中的Fragment
  81. mViewPager.setCurrentItem(position);
  82. resetImgs();
  83. selectTab(position);
  84. }
  85.  
  86. @Override
  87. //页面滚动状态改变事件
  88. public void onPageScrollStateChanged(int state) {
  89.  
  90. }
  91. });
  92. }
  93.  
  94. private void initEvents() {
  95. //设置四个Tab的点击事件
  96. mTabWeixin.setOnClickListener(this);
  97. mTabFrd.setOnClickListener(this);
  98. mTabAddress.setOnClickListener(this);
  99. mTabSetting.setOnClickListener(this);
  100.  
  101. }
  102.  
  103. //初始化控件
  104. private void initViews() {
  105. mViewPager = (ViewPager) findViewById(R.id.id_viewpager);
  106.  
  107. mTabWeixin = (LinearLayout) findViewById(R.id.id_tab_weixin);
  108. mTabFrd = (LinearLayout) findViewById(R.id.id_tab_frd);
  109. mTabAddress = (LinearLayout) findViewById(R.id.id_tab_address);
  110. mTabSetting = (LinearLayout) findViewById(R.id.id_tab_setting);
  111.  
  112. mImgWeixin = (ImageButton) findViewById(R.id.id_tab_weixin_img);
  113. mImgFrd = (ImageButton) findViewById(R.id.id_tab_frd_img);
  114. mImgAddress = (ImageButton) findViewById(R.id.id_tab_address_img);
  115. mImgSetting = (ImageButton) findViewById(R.id.id_tab_setting_img);
  116.  
  117. }
  118.  
  119. @Override
  120. public void onClick(View v) {
  121. //先将四个ImageButton置为灰色
  122. resetImgs();
  123.  
  124. //根据点击的Tab切换不同的页面及设置对应的ImageButton为绿色
  125. switch (v.getId()) {
  126. case R.id.id_tab_weixin:
  127. selectTab(0);
  128. break;
  129. case R.id.id_tab_frd:
  130. selectTab(1);
  131. break;
  132. case R.id.id_tab_address:
  133. selectTab(2);
  134. break;
  135. case R.id.id_tab_setting:
  136. selectTab(3);
  137. break;
  138. }
  139. }
  140.  
  141. private void selectTab(int i) {
  142. //根据点击的Tab设置对应的ImageButton为绿色
  143. switch (i) {
  144. case 0:
  145. mImgWeixin.setImageResource(R.mipmap.tab_weixin_pressed);
  146. break;
  147. case 1:
  148. mImgFrd.setImageResource(R.mipmap.tab_find_frd_pressed);
  149. break;
  150. case 2:
  151. mImgAddress.setImageResource(R.mipmap.tab_address_pressed);
  152. break;
  153. case 3:
  154. mImgSetting.setImageResource(R.mipmap.tab_settings_pressed);
  155. break;
  156. }
  157. //设置当前点击的Tab所对应的页面
  158. mViewPager.setCurrentItem(i);
  159. }
  160.  
  161. //将四个ImageButton设置为灰色
  162. private void resetImgs() {
  163. mImgWeixin.setImageResource(R.mipmap.tab_weixin_normal);
  164. mImgFrd.setImageResource(R.mipmap.tab_find_frd_normal);
  165. mImgAddress.setImageResource(R.mipmap.tab_address_normal);
  166. mImgSetting.setImageResource(R.mipmap.tab_settings_normal);
  167. }
  168. }

SettingFragment.java

  1. package com.example.wenandroidcheck11;
  2.  
  3. import android.os.Bundle;
  4. import android.view.LayoutInflater;
  5. import android.view.View;
  6. import android.view.ViewGroup;
  7. import androidx.annotation.Nullable;
  8. import androidx.fragment.app.Fragment;
  9.  
  10. public class SettingFragment extends Fragment {
  11. @Nullable
  12. @Override
  13. public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
  14. View view = inflater.inflate(R.layout.tab4, container, false);
  15. return view;
  16. }
  17. }

WeixinFragment.java

  1. package com.example.wenandroidcheck11;
  2. import android.os.Bundle;
  3. import android.view.LayoutInflater;
  4. import android.view.View;
  5. import android.view.ViewGroup;
  6. import androidx.annotation.Nullable;
  7. import androidx.fragment.app.Fragment;
  8.  
  9. public class WeixinFragment extends Fragment {
  10. @Nullable
  11. @Override
  12. public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
  13. View view = inflater.inflate(R.layout.tab1, container, false);
  14. return view;
  15. }
  16. }

FrdFragment.java

  1. package com.example.wenandroidcheck11;
  2. import android.os.Bundle;
  3. import android.view.LayoutInflater;
  4. import android.view.View;
  5. import android.view.ViewGroup;
  6. import androidx.annotation.Nullable;
  7. import androidx.fragment.app.Fragment;
  8. public class FrdFragment extends Fragment {
  9. @Nullable
  10. @Override
  11. public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
  12. View view = inflater.inflate(R.layout.tab2, container, false);
  13. return view;
  14. }
  15. }

AddressFragment.java

  1. package com.example.wenandroidcheck11;
  2. import android.os.Bundle;
  3. import android.view.LayoutInflater;
  4. import android.view.View;
  5. import android.view.ViewGroup;
  6. import androidx.annotation.Nullable;
  7. import androidx.fragment.app.Fragment;
  8. public class AddressFragment extends Fragment {
  9. @Nullable
  10. @Override
  11. public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
  12. View view = inflater.inflate(R.layout.tab3, container, false);
  13. return view;
  14. }
  15. }

activity_main.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout
  3. xmlns:android="http://schemas.android.com/apk/res/android"
  4. xmlns:tools="http://schemas.android.com/tools"
  5.  
  6. android:orientation="vertical"
  7. android:layout_width="match_parent"
  8. android:layout_height="match_parent"
  9. tools:context=".MainActivity">
  10.  
  11. <include layout="@layout/top"/>
  12. <androidx.viewpager.widget.ViewPager
  13. android:id="@+id/id_viewpager"
  14. android:layout_width="match_parent"
  15. android:layout_height="0dp"
  16. android:layout_weight="1">
  17. </androidx.viewpager.widget.ViewPager>
  18.  
  19. <include layout="@layout/bottom"/>
  20. </LinearLayout>

bottom.xml

  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="55dp"
  5. android:gravity="center"
  6. android:background="@color/material_blue_grey_800"
  7. android:orientation="horizontal">
  8.  
  9. <LinearLayout
  10. android:layout_width="0dp"
  11. android:layout_height="wrap_content"
  12. android:layout_weight="1"
  13. android:id="@+id/id_tab_weixin"
  14. android:gravity="center"
  15. android:orientation="vertical">
  16.  
  17. <ImageButton
  18. android:id="@+id/id_tab_weixin_img"
  19. android:clickable="false"
  20. android:layout_width="wrap_content"
  21. android:layout_height="wrap_content"
  22. android:src="@mipmap/tab_weixin_pressed"
  23. android:background="#00000000"/>
  24. <TextView
  25. android:layout_width="wrap_content"
  26. android:layout_height="wrap_content"
  27. android:textColor="#ffffff"
  28. android:text="微信"/>
  29. </LinearLayout>
  30. <LinearLayout
  31. android:id="@+id/id_tab_frd"
  32. android:layout_width="0dp"
  33. android:layout_height="wrap_content"
  34. android:layout_weight="1"
  35. android:gravity="center"
  36. android:orientation="vertical">
  37.  
  38. <ImageButton
  39. android:id="@+id/id_tab_frd_img"
  40. android:clickable="false"
  41. android:layout_width="wrap_content"
  42. android:layout_height="wrap_content"
  43. android:src="@mipmap/tab_find_frd_normal"
  44. android:background="#00000000"/>
  45. <TextView
  46. android:layout_width="wrap_content"
  47. android:layout_height="wrap_content"
  48. android:textColor="#ffffff"
  49. android:text="朋友"/>
  50. </LinearLayout>
  51. <LinearLayout
  52. android:id="@+id/id_tab_address"
  53. android:layout_width="0dp"
  54. android:layout_height="wrap_content"
  55. android:layout_weight="1"
  56. android:gravity="center"
  57. android:orientation="vertical">
  58.  
  59. <ImageButton
  60. android:id="@+id/id_tab_address_img"
  61. android:clickable="false"
  62. android:layout_width="wrap_content"
  63. android:layout_height="wrap_content"
  64. android:src="@mipmap/tab_address_normal"
  65. android:background="#00000000"/>
  66. <TextView
  67. android:layout_width="wrap_content"
  68. android:layout_height="wrap_content"
  69. android:textColor="#ffffff"
  70. android:text="通讯录"/>
  71. </LinearLayout>
  72. <LinearLayout
  73. android:id="@+id/id_tab_setting"
  74. android:layout_width="0dp"
  75. android:layout_height="wrap_content"
  76. android:layout_weight="1"
  77. android:gravity="center"
  78. android:orientation="vertical">
  79.  
  80. <ImageButton
  81. android:id="@+id/id_tab_setting_img"
  82. android:clickable="false"
  83. android:layout_width="wrap_content"
  84. android:layout_height="wrap_content"
  85. android:src="@mipmap/tab_settings_normal"
  86. android:background="#00000000"/>
  87. <TextView
  88. android:layout_width="wrap_content"
  89. android:layout_height="wrap_content"
  90. android:textColor="#ffffff"
  91. android:text="设置"/>
  92. </LinearLayout>
  93.  
  94. </LinearLayout>

dialog_data.xml

  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="wrap_content"
  5. android:gravity="center_horizontal"
  6. android:orientation="vertical">
  7.  
  8. <DatePicker
  9. android:id="@+id/datePicker"
  10. android:layout_width="match_parent"
  11. android:layout_height="wrap_content"
  12. android:calendarViewShown="false"
  13. android:endYear="2027"
  14. android:startYear="2007" />
  15. </LinearLayout>

dialog_time.xml

  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="wrap_content"
  5. android:gravity="center"
  6. android:orientation="vertical">
  7.  
  8. <TimePicker
  9. android:id="@+id/timePicker"
  10. android:layout_width="match_parent"
  11. android:layout_height="wrap_content"></TimePicker>
  12.  
  13. </LinearLayout>

tab1.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:orientation="vertical"
  4. android:layout_width="match_parent"
  5. android:layout_height="match_parent">
  6. <TextView
  7. android:id="@+id/texnum1"
  8. android:layout_width="match_parent"
  9. android:layout_height="wrap_content"
  10. android:text="添加新的小账单"
  11. android:textSize="30dp"
  12. android:gravity="center_horizontal"
  13. android:padding="5dp"
  14. android:background="@color/baise"
  15. android:layout_marginBottom="10dp"
  16. />
  17.  
  18. <LinearLayout
  19. android:id="@+id/ming"
  20. android:layout_width="match_parent"
  21. android:layout_height="wrap_content"
  22. android:orientation="horizontal">
  23.  
  24. <TextView
  25. android:layout_width="wrap_content"
  26. android:layout_height="wrap_content"
  27. android:text="对应的金额:"
  28. android:padding="8dp"
  29. android:background="@color/qianhuang"
  30. android:layout_marginRight="5dp"
  31. android:textSize="18sp" />
  32.  
  33. <EditText
  34. android:layout_width="match_parent"
  35. android:layout_height="wrap_content"
  36. android:hint="请输入相应的金额"
  37. android:inputType="number"
  38. android:lines="2"
  39. android:padding="8dp"
  40. android:background="@color/baise"
  41. android:layout_marginBottom="10dp"
  42. />
  43.  
  44. </LinearLayout>
  45.  
  46. <EditText
  47. android:layout_width="match_parent"
  48. android:layout_height="wrap_content"
  49. android:hint="请输入新账单的相关内容"
  50. android:lines="12"
  51. android:padding="8dp"
  52. android:background="@color/baise"
  53. android:layout_marginBottom="10dp"
  54. android:inputType="textMultiLine"
  55. android:gravity="top"
  56. />
  57.  
  58. <LinearLayout
  59. android:id="@+id/ll_date"
  60. android:layout_width="match_parent"
  61. android:layout_height="wrap_content"
  62. android:orientation="horizontal">
  63.  
  64. <TextView
  65. android:layout_width="wrap_content"
  66. android:layout_height="wrap_content"
  67. android:text="选择日期:"
  68. android:padding="8dp"
  69. android:background="@color/baise"
  70. android:textSize="18sp" />
  71.  
  72. <TextView
  73. android:id="@+id/tv_date"
  74. android:layout_width="match_parent"
  75. android:layout_height="wrap_content"
  76. android:padding="8dp"
  77. android:background="@color/qianhuang"
  78. android:textSize="18sp" />
  79.  
  80. </LinearLayout>
  81.  
  82. <LinearLayout
  83. android:id="@+id/ll_time"
  84. android:layout_width="match_parent"
  85. android:layout_height="wrap_content"
  86. android:layout_marginTop="10dp"
  87. android:orientation="horizontal">
  88.  
  89. <TextView
  90. android:layout_width="wrap_content"
  91. android:layout_height="wrap_content"
  92. android:text="选择时间:"
  93. android:padding="8dp"
  94. android:background="@color/baise"
  95. android:textSize="18sp" />
  96.  
  97. <TextView
  98. android:id="@+id/tv_time"
  99. android:layout_width="match_parent"
  100. android:layout_height="wrap_content"
  101. android:background="@color/qianhuang"
  102. android:padding="8dp"
  103. android:layout_marginBottom="10dp"
  104. android:textSize="18sp" />
  105.  
  106. </LinearLayout>
  107. <TextView
  108. android:id="@+id/age"
  109. android:layout_width="wrap_content"
  110. android:layout_height="wrap_content"
  111. android:text="@string/wen5"
  112. android:background="@color/chengse"
  113. android:layout_marginBottom="10dp"
  114. android:textSize="25sp" />
  115.  
  116. <RadioGroup
  117. android:layout_width="wrap_content"
  118. android:layout_height="wrap_content"
  119. android:id="@+id/radGrpAge"
  120. android:orientation="horizontal"
  121. android:textSize="30sp"
  122. android:checkedButton="@+id/radBtnAgeRange1">
  123. <RadioButton
  124. android:id="@+id/radBtnAgeRange1"
  125. android:textSize="20sp"
  126. android:layout_height="wrap_content"
  127. android:layout_width="wrap_content"
  128. android:text="@string/wen1"/>
  129. <RadioButton
  130. android:id="@+id/radBtnAgeRange2"
  131. android:textSize="20sp"
  132. android:layout_height="wrap_content"
  133. android:layout_width="wrap_content"
  134. android:text="@string/wen2"/>
  135. <RadioButton
  136. android:id="@+id/radBtnAgeRange3"
  137. android:textSize="20sp"
  138. android:layout_height="wrap_content"
  139. android:layout_width="wrap_content"
  140. android:text="@string/wen3"/>
  141. <RadioButton
  142. android:id="@+id/radBtnAgeRange4"
  143. android:textSize="20sp"
  144. android:layout_height="wrap_content"
  145. android:layout_width="wrap_content"
  146. android:text="@string/wen4"/>
  147. </RadioGroup>
  148. <LinearLayout
  149. android:id="@+id/wenbut"
  150. android:layout_width="match_parent"
  151. android:layout_height="wrap_content"
  152. android:layout_marginTop="10dp"
  153. android:orientation="horizontal">
  154. <Button
  155. android:id="@+id/wenbut1"
  156. android:layout_width="wrap_content"
  157. android:layout_height="wrap_content"
  158. android:text="返回"
  159. android:background="#87CEFA"
  160. android:layout_marginLeft="50dp"
  161. />
  162. <Button
  163. android:id="@+id/wenbut2"
  164. android:layout_width="wrap_content"
  165. android:layout_height="wrap_content"
  166. android:text="确认"
  167. android:background="#87CEFA"
  168. android:layout_marginLeft="50dp"
  169. />
  170.  
  171. </LinearLayout>
  172. </LinearLayout>

tab2.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:app="http://schemas.android.com/apk/res-auto"
  4. android:orientation="vertical"
  5. android:layout_width="match_parent"
  6. android:layout_height="match_parent">
  7.  
  8. <TextView
  9. android:layout_marginTop="60dp"
  10. android:id="@+id/reg_number1"
  11. android:layout_width="wrap_content"
  12. android:layout_height="wrap_content"
  13. android:padding="10dp"
  14. android:text="账号:"
  15. android:textColor="#000"
  16. android:textSize="20dp" />
  17. <EditText
  18. android:layout_alignBottom="@+id/reg_number1"
  19. android:layout_toRightOf="@+id/reg_number1"
  20. android:id="@+id/reg_username"
  21. android:layout_width="match_parent"
  22. android:layout_height="wrap_content"
  23. android:hint="请输入用户名"
  24. android:padding="10dp" />
  25. <TextView
  26. android:id="@+id/reg_number2"
  27. android:layout_marginTop="5dp"
  28. android:layout_width="wrap_content"
  29. android:layout_height="wrap_content"
  30. android:layout_below="@+id/reg_number1"
  31. android:padding="10dp"
  32. android:text="密码1:"
  33. android:textColor="#000"
  34. android:textSize="20dp" />
  35. <EditText
  36. android:layout_alignBottom="@id/reg_number2"
  37. android:layout_toRightOf="@+id/reg_number2"
  38. android:id="@+id/reg_password"
  39. android:layout_width="match_parent"
  40. android:layout_height="wrap_content"
  41. android:hint="请输入新的密码"
  42. android:padding="10dp" />
  43. <TextView
  44. android:id="@+id/reg_number3"
  45. android:layout_marginTop="5dp"
  46. android:layout_width="wrap_content"
  47. android:layout_height="wrap_content"
  48. android:layout_below="@+id/reg_number2"
  49. android:padding="10dp"
  50. android:text="密码2:"
  51. android:textColor="#000"
  52. android:textSize="20dp" />
  53. <EditText
  54. android:layout_alignBottom="@id/reg_number3"
  55. android:layout_toRightOf="@+id/reg_number3"
  56. android:id="@+id/reg_password2"
  57. android:layout_width="match_parent"
  58. android:layout_height="wrap_content"
  59. android:hint="请在此确认新的密码"
  60. android:padding="10dp" />
  61. <TextView
  62. android:id="@+id/reg_number4"
  63. android:layout_marginTop="5dp"
  64. android:layout_width="wrap_content"
  65. android:layout_height="wrap_content"
  66. android:layout_below="@+id/reg_number3"
  67. android:padding="10dp"
  68. android:text="邮箱:"
  69. android:textColor="#000"
  70. android:textSize="20dp" />
  71. <EditText
  72. android:layout_alignBottom="@id/reg_number4"
  73. android:layout_toRightOf="@+id/reg_number4"
  74. android:id="@+id/reg_mail"
  75. android:layout_width="match_parent"
  76. android:layout_height="wrap_content"
  77. android:hint="请输入邮箱"
  78. android:padding="10dp" />
  79.  
  80. <Button
  81. android:layout_width="wrap_content"
  82. android:layout_height="wrap_content"
  83. android:text="确定注册"
  84. android:background="#74e674"
  85. android:id="@+id/reg_btn_sure"
  86. android:layout_marginTop="38dp"
  87. android:layout_below="@+id/reg_mail"
  88. android:layout_marginLeft="90dp" />
  89.  
  90. <Button
  91. android:layout_width="wrap_content"
  92. android:layout_height="wrap_content"
  93. android:text="返回登录"
  94. android:background="#f27758"
  95. android:id="@+id/reg_btn_login"
  96. android:layout_alignBottom="@id/reg_btn_sure"
  97. android:layout_toRightOf="@id/reg_btn_sure"
  98. android:layout_marginLeft="40dp"
  99. />
  100. <TextView
  101. android:layout_width="wrap_content"
  102. android:layout_height="wrap_content"
  103. android:layout_centerHorizontal="true"
  104. android:text="账号注册"
  105. android:textSize="30dp"
  106. android:layout_marginTop="5dp"
  107. />
  108. </RelativeLayout>

tab3.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:orientation="vertical"
  4. android:layout_width="match_parent"
  5. android:layout_height="match_parent">
  6. <TextView
  7. android:layout_width="match_parent"
  8. android:layout_height="match_parent"
  9. android:gravity="center"
  10. android:textSize="30sp"
  11. android:text="The Address Tab!"/>
  12. </LinearLayout>

tab4.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:orientation="vertical"
  4. android:layout_width="match_parent"
  5. android:layout_height="match_parent">
  6. <TextView
  7. android:layout_width="match_parent"
  8. android:layout_height="match_parent"
  9. android:gravity="center"
  10. android:textSize="30sp"
  11. android:text="The Setting Tab!"/>
  12. </LinearLayout>

top.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:orientation="vertical"
  4. android:background="@android:drawable/title_bar"
  5. android:gravity="center"
  6. android:layout_width="match_parent"
  7. android:layout_height="45dp">
  8.  
  9. <TextView
  10. android:layout_width="wrap_content"
  11. android:layout_height="wrap_content"
  12. android:text="微信"
  13. android:textColor="#ffffff"
  14. android:textSize="20sp"
  15. android:textStyle="bold"/>
  16.  
  17. </LinearLayout>

其次就是关于一些mipmap、colors、strings、的相关的使用。在此就不一一介绍了。

使用tap、Fragment等相关相关知识点。实现类似微信的界面的更多相关文章

  1. android学习相关intent和fragment的先关知识点

    对于使用intent,主要是用来进行活动之间的跳转,然后就是通过intent向下一个活动传递数据,还有就是想上一个活动传递数据. 实例: 先添加按钮的点击事件,当点击按钮时进行事件的触发,主要代码是 ...

  2. dubbo相关的知识点总结

    dubbo最近提交到了apache,成为了apache的孵化项目,又开始活跃起来了.就官方在git上面的说明文档和其他资料,学习总结以下dubbo的一些知识点. .The dubbo protocol ...

  3. ksar、sar及相关内核知识点解析

    关键词:sar.sadc.ksar./proc/stat./proc/cpuinfo./proc/meminfo./proc/diskstats. 在之前有简单介绍过sar/ksar,最近在使用中感觉 ...

  4. Hbase框架原理及相关的知识点理解、Hbase访问MapReduce、Hbase访问Java API、Hbase shell及Hbase性能优化总结

    转自:http://blog.csdn.net/zhongwen7710/article/details/39577431 本blog的内容包含: 第一部分:Hbase框架原理理解 第二部分:Hbas ...

  5. Python基础总结之第八天开始【while循环以及for循环,循环嵌套等循环相关的知识点】(新手可相互督促)

    ennnnn,年薪20万的梦想是不是又进了一步: 循环,什么是循环,循环就是电池有电,手机屏幕可以循环一整天的使用:循环就是地球不毁灭,太阳日复一日的出现...... 不接受反驳,谢谢!~ 只要条件满 ...

  6. python相关遗漏知识点补充

    python中的相关帮助命令 假设s是一个字符串, 那么dir(s)可以列出字符串对象的所有属性(方法也是函数属性),其中有下划线的部分与类重 载有关,用来表示python实现细节,没有下划线的属性是 ...

  7. mysql 和字符串截取相关的知识点

    LOCATE(',','123,456') - 1) SELECT LEFT('123,456',3); SELECT LEFT('123,456',LOCATE(',','123,456') - 1 ...

  8. Oracle相关的知识点

    1. 如何在Oracle SQLPlus中执行SQL Script文件 以下面的格式在提示符中输入@{file name} SQL>@{file} 假设你要运行的文件的名字是script.sql ...

  9. 与html相关的知识点整理

    梳理html时发现的一些问题.总结一下,答案大都从网上找来. 一.html 与 htm 的区别 没有本质的区别..htm是在win32时代,系统只能识别3位扩展名时使用的.现在一般都使用.html. ...

随机推荐

  1. C++ 函数模板/类模板

    #include <iostream> #include <vector> using namespace std; template < class T > // ...

  2. TCP/IP协议基本知识

    1.TCP/IP协议中主机与主机之间通信的三要素: IP地址(IP address) 子网掩码(subnet mask) IP路由(IP router) 2.IP地址的分类及每一类的范围: A类1-1 ...

  3. (转)C++中的new

    转载自:http://blog.csdn.net/sparkliang/article/details/3650324 C++中的new其实是一个很糊弄人的术语,它有两种不同的含义,new运算符(ne ...

  4. 【springboot spring mybatis】看我怎么将springboot与spring整合mybatis与druid数据源

    目录 概述 1.mybatis 2.druid 壹:spring整合 2.jdbc.properties 3.mybatis-config.xml 二:java代码 1.mapper 2.servic ...

  5. 关于Idea中不能使用Scanner在console

    遇到了麻烦,在Idea中使用@Test运行程序时,scanner在控制台无法输入,然后来回折腾... 创建了一个新的类里面含有main方法,可以完美运行scanner: 重新回来,发现还是不行, 创建 ...

  6. python高阶函数&异常处理

    高阶函数 1.什么是高阶函数 在Python中,变量可以指向函数 函数名也是变量 既然变量可以指向函数,函数的参数能接收变量,那么一个函数就可以接收另一个函数作为参数,这种函数就称之为高阶函数. ma ...

  7. C++类复习及新的认识 6.1.1+6.1.2内容(适合看过一遍书的新手)

    作者水平有限,文字表述大多摘抄课本,源码部分由课本加自己改编而成,所有代码均在vs2019中编译通过 定义类操作 class Tdate { public: void Set(int m, int d ...

  8. go:内置函数 | 闭包 | 数组 | 切片 | 排序 | map | 锁

    内置函数 1.close: 主要是用来关闭channel 2.len:用来求长度,比如string.array.slice.map.channel 3.new与make都是用来分配内存 new用来分配 ...

  9. 解决WSL在执行32位程序时报错“Exec format error”的问题

    当你尝试在WSL上运行32位的程序时,shell将会报错:cannot execute binary file: Exec format error. 这是因为WSL目前暂不支持32位的ELF可执行文 ...

  10. 《数据库优化》- MySQL视图

    一.什么是视图 视图,是基于一个表或多个表或视图的逻辑表,本身不包含数据,通过它可以对表里面的数据进行查询和修改,视图基于的表称为基表.视图是存储在数据字典里的一条select语句. 通俗地讲,视图就 ...