您的位置:首页 > 汽车 > 新车 > 游戏网络游戏_厦门seo计费_北京网站建设公司报价_系统优化大师

游戏网络游戏_厦门seo计费_北京网站建设公司报价_系统优化大师

2024/11/17 0:30:40 来源:https://blog.csdn.net/cf8833/article/details/143159485  浏览:    关键词:游戏网络游戏_厦门seo计费_北京网站建设公司报价_系统优化大师
游戏网络游戏_厦门seo计费_北京网站建设公司报价_系统优化大师

说明:kotlin + tablayout + viewpager + adapter实现滑动界面

效果图
在这里插入图片描述

step1:

package com.example.flushfragmentdemoimport androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator
import kotlinx.android.synthetic.main.activity_main.*class MainActivity : AppCompatActivity() {override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)setContentView(R.layout.activity_main)val fragments = ArrayList<Fragment>()fragments.add(FooFragment())fragments.add(PlayerFragment(""))mainViewPager.apply {adapter = object :FragmentStateAdapter(this@MainActivity){override fun getItemCount(): Int {return 2}override fun createFragment(position: Int): Fragment {return fragments[position]}}setCurrentItem(1,false)}TabLayoutMediator(tabLayout,mainViewPager){ tab: TabLayout.Tab, i: Int ->when (i) {0 -> tab.text = "fpp"1 -> tab.text = "player"}}.attach()}
}

step2:

package com.example.flushfragmentdemoimport android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroupprivate const val ARG_PARAM1 = "param1"
private const val ARG_PARAM2 = "param2"class FooFragment : Fragment() {private var param1: String? = nullprivate var param2: String? = nulloverride fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)arguments?.let {param1 = it.getString(ARG_PARAM1)param2 = it.getString(ARG_PARAM2)}}override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,savedInstanceState: Bundle?): View? {return inflater.inflate(R.layout.fragment_foo, container, false)}companion object {@JvmStaticfun newInstance(param1: String, param2: String) =FooFragment().apply {arguments = Bundle().apply {putString(ARG_PARAM1, param1)putString(ARG_PARAM2, param2)}}}
}

step3:

package com.example.flushfragmentdemoimport android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflaterimport android.view.View
import android.view.ViewGroup
import kotlinx.android.synthetic.main.fragment_player.*class PlayerFragment(private val url:String) : Fragment() {override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,savedInstanceState: Bundle?): View? {// Inflate the layout for this fragmentreturn inflater.inflate(R.layout.fragment_player, container, false)}override fun onViewCreated(view: View, savedInstanceState: Bundle?) {super.onViewCreated(view, savedInstanceState)}override fun onResume() {super.onResume()}override fun onPause() {super.onPause()}
}

step4:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"tools:context=".MainActivity"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><com.google.android.material.appbar.AppBarLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"><com.google.android.material.tabs.TabLayoutandroid:id="@+id/tabLayout"android:layout_width="match_parent"android:layout_height="wrap_content"app:tabIndicatorColor="@android:color/white" /></com.google.android.material.appbar.AppBarLayout><androidx.viewpager2.widget.ViewPager2android:id="@+id/mainViewPager"android:layout_width="match_parent"android:layout_height="match_parent"app:layout_anchorGravity="bottom" /></LinearLayout></androidx.constraintlayout.widget.ConstraintLayout>

step5:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:background="@android:color/holo_green_dark"tools:context=".FooFragment"><!-- TODO: Update blank fragment layout --><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:gravity="center"android:background="@android:color/holo_red_dark"android:text="fpp"android:textSize="30sp" /></FrameLayout>

step6:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:background="@android:color/holo_orange_dark"tools:context=".FooFragment"><!-- TODO: Update blank fragment layout --><TextViewandroid:layout_width="match_parent"android:layout_height="match_parent"android:gravity="center"android:text="player"android:textSize="30sp" /></FrameLayout>

end

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com