做个笔记,有错误的地方请指点!
有两种类型主界面页的切换:
第一种是FragmentTransaction和Fragment;
第二种是ViewPager和FragmentPagerAdapter;
效果差不多,都可以点击切换,但第二种可以左右滑动切换,
第一种FragmentTransaction和Fragment实现:
效果图:
act_tab1.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#abcabc"
android:orientation="vertical">
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
</FrameLayout>
<LinearLayout
android:id="@+id/bottomPanel"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#FFFFFF"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/ll_home"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/iv_home"
android:layout_width="26dp"
android:layout_height="26dp"
android:src="https://blog.csdn.net/@drawable/home_selected" />
<TextView
android:id="@+id/tv_home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:gravity="center"
android:text="首页"
android:textColor="#ff7700" />
</LinearLayout>
<LinearLayout
android:id="@+id/ll_live"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/iv_live"
android:layout_width="26dp"
android:layout_height="26dp"
android:src="https://blog.csdn.net/@drawable/live_selector" />
<TextView
android:id="@+id/tv_live"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:gravity="center"
android:text="直播"
android:textColor="#aaaaaa" />
</LinearLayout>
<LinearLayout
android:id="@+id/ll_follow"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/iv_follow"
android:layout_width="26dp"
android:layout_height="26dp"
android:src="https://blog.csdn.net/@drawable/follow_selector" />
<TextView
android:id="@+id/tv_follow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:gravity="center"
android:text="关注"
android:textColor="#aaaaaa" />
</LinearLayout>
<LinearLayout
android:id="@+id/ll_discover"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/iv_discover"
android:layout_width="26dp"
android:layout_height="26dp"
android:src="https://blog.csdn.net/@drawable/discover_selector" />
<TextView
android:id="@+id/tv_discover"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:gravity="center"
android:text="发现"
android:textColor="#aaaaaa" />
</LinearLayout>
<LinearLayout
android:id="@+id/ll_user"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="

这篇博客主要记录了两种Android主界面的实现方式:使用FragmentTransaction和Fragment进行页面切换,以及借助ViewPager和FragmentPagerAdapter实现可滑动切换的主界面。第一种方式通过点击切换,第二种则支持手势滑动切换。
1万+

被折叠的 条评论
为什么被折叠?



