Commit 4e78560b authored by mengcuiguang's avatar mengcuiguang

代码优化

parent 68b4b32d
package com.mints.goodmoney.ui.adapter
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.mints.goodmoney.R
class XmlyPageAdapter(val xmlyPageList: Any?) :
RecyclerView.Adapter<XmlyPageAdapter.ViewHolder>() {
lateinit var context: Context
lateinit var mOnItemClickListener: OnItemClickListener
inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
context = parent.context
val view = LayoutInflater.from(context).inflate(R.layout.item_rv_xmly_page, parent, false)
val viewHolder = ViewHolder(view)
return viewHolder
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.itemView.setTag(position)
}
// override fun getItemCount() = xmlyPageList?.size
override fun getItemCount() = 10
interface OnItemClickListener {
fun onItemClick(position: Int)
}
fun setOnItemClickListener(listener: OnItemClickListener) {
mOnItemClickListener = listener
}
}
\ No newline at end of file
......@@ -44,7 +44,7 @@ class MoneyFragment : BaseFragment(), XTabLayout.OnTabSelectedListener {
override fun onHiddenChanged(hidden: Boolean) {
if (curPosition == 0) {
mainFragment?.onHiddenChanged(hidden)
} else if (curPosition == 4) {
} else if (curPosition == 3) {
liebaoGameFragment?.onHiddenChanged(hidden)
}
super.onHiddenChanged(hidden)
......@@ -90,20 +90,20 @@ class MoneyFragment : BaseFragment(), XTabLayout.OnTabSelectedListener {
currentFragment = mainFragment
}
xtFragmentMoney.setxTabDisplayNum(5)
xtFragmentMoney.setxTabDisplayNum(4)
val newTab1 = xtFragmentMoney.newTab()
newTab1.text = "视频"
val newTab2 = xtFragmentMoney.newTab()
newTab2.text = "书城"
val newTab3 = xtFragmentMoney.newTab()
newTab3.text = "新闻"
// val newTab3 = xtFragmentMoney.newTab()
// newTab3.text = "新闻"
val newTab4 = xtFragmentMoney.newTab()
newTab4.text = "听书"
val newTab5 = xtFragmentMoney.newTab()
newTab5.text = "游戏"
xtFragmentMoney.addTab(newTab1)
xtFragmentMoney.addTab(newTab2)
xtFragmentMoney.addTab(newTab3)
// xtFragmentMoney.addTab(newTab3)
xtFragmentMoney.addTab(newTab4)
xtFragmentMoney.addTab(newTab5)
xtFragmentMoney.addOnTabSelectedListener(this)
......@@ -172,19 +172,19 @@ class MoneyFragment : BaseFragment(), XTabLayout.OnTabSelectedListener {
}
addOrShowFragment(childFragmentManager, bookStoreFragment!!, FRAGMENT_TAG_BOOKSTORE)
}
// 2 -> {
// if (newsFragment == null) {
// newsFragment = RsNewsFragment()
// }
// addOrShowFragment(childFragmentManager, newsFragment!!, FRAGMENT_TAG_NEWS)
// }
2 -> {
if (newsFragment == null) {
newsFragment = RsNewsFragment()
}
addOrShowFragment(childFragmentManager, newsFragment!!, FRAGMENT_TAG_NEWS)
}
3 -> {
if (xmlyGameFragment == null) {
xmlyGameFragment = XmlyFragment()
}
addOrShowFragment(childFragmentManager, xmlyGameFragment!!, FRAGMENT_TAG_XMLY)
}
4 -> {
3 -> {
if (liebaoGameFragment == null) {
liebaoGameFragment = LiebaoGameFragment()
}
......
package com.mints.goodmoney.ui.fragment
import androidx.recyclerview.widget.GridLayoutManager
import com.mints.goodmoney.R
import com.mints.goodmoney.ui.adapter.XmlyPageAdapter
import com.mints.goodmoney.ui.fragment.base.LazyLoadBaseFragment
import kotlinx.android.synthetic.main.fragment_main_xmly_page.*
/**
* 描述:喜马拉雅封面
......@@ -9,9 +12,12 @@ import com.mints.goodmoney.ui.fragment.base.LazyLoadBaseFragment
*/
class XmlyPageFragment(val data: Int) : LazyLoadBaseFragment() {
private lateinit var xmlyPageAdapter: XmlyPageAdapter
override fun getContentViewLayoutID() = R.layout.fragment_main_xmly_page
override fun initViewsAndEvents() {
}
override fun onFragmentFirstVisible() {
......@@ -19,8 +25,15 @@ class XmlyPageFragment(val data: Int) : LazyLoadBaseFragment() {
showToast("" + data)
//recyclerview 加载封面
initRvView()
//recyclerview 事件监听
}
private fun initRvView() {
val gridLayoutManager = GridLayoutManager(context, 2)
xmlyPageVip.layoutManager = gridLayoutManager
xmlyPageAdapter = XmlyPageAdapter(null)
xmlyPageVip.adapter = xmlyPageAdapter
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<com.mints.goodmoney.ui.widgets.MyViewPager xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/vpFragmentXmly"
android:background="#0f0"
android:id="@+id/xmlyPageVip"
android:layout_width="match_parent"
android:layout_height="match_parent" />
\ No newline at end of file
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:background="@null"
android:overScrollMode="never" />
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="wrap_content"
android:gravity="center_horizontal"
android:background="#0f0"
android:layout_margin="10dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:layout_marginBottom="16dp"
android:textSize="14sp"
android:textColor="@color/black"
android:text="原价:123" />
</LinearLayout>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment