Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
android_freeworld
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
android
android_freeworld
Commits
e0fb1ad6
Commit
e0fb1ad6
authored
Jul 05, 2021
by
fengruiyu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
首页的tab和viewpager的功能已完成
parent
2f63540d
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
202 additions
and
16 deletions
+202
-16
.gitignore
.gitignore
+2
-1
HomeFragment.kt
...rc/main/java/com/mints/goodnews/main/home/HomeFragment.kt
+142
-1
fragment_home.xml
app/src/main/res/layout/fragment_home.xml
+14
-11
home_tab_item.xml
app/src/main/res/layout/home_tab_item.xml
+10
-0
config.gradle
config.gradle
+3
-1
build.gradle
library_base/build.gradle
+2
-0
ScaleTransitionPagerTitleView.kt
...java/com/fry/base/widget/ScaleTransitionPagerTitleView.kt
+27
-0
version.properties
library_base/version.properties
+2
-2
No files found.
.gitignore
View file @
e0fb1ad6
...
...
@@ -12,4 +12,5 @@
/build
/captures
.externalNativeBuild
.cxx
\ No newline at end of file
.cxx
/library_ad/build/
app/src/main/java/com/mints/goodnews/main/home/HomeFragment.kt
View file @
e0fb1ad6
package
com.mints.goodnews.main.home
import
android.content.Context
import
android.graphics.Color
import
android.graphics.Typeface
import
android.os.Bundle
import
android.view.LayoutInflater
import
android.view.ViewGroup
import
android.view.animation.AccelerateInterpolator
import
android.view.animation.DecelerateInterpolator
import
androidx.core.content.ContextCompat
import
androidx.fragment.app.Fragment
import
androidx.viewpager2.adapter.FragmentStateAdapter
import
androidx.viewpager2.widget.ViewPager2
import
com.fry.base.base.BaseFragment
import
com.fry.base.widget.ScaleTransitionPagerTitleView
import
com.mints.goodnews.BR
import
com.mints.goodnews.R
import
com.mints.goodnews.databinding.FragmentHomeBinding
import
com.mints.goodnews.main.my.MyFragment
import
me.goldze.mvvmhabit.utils.Utils
import
net.lucode.hackware.magicindicator.MagicIndicator
import
net.lucode.hackware.magicindicator.buildins.UIUtil
import
net.lucode.hackware.magicindicator.buildins.commonnavigator.CommonNavigator
import
net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter
import
net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerIndicator
import
net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView
import
net.lucode.hackware.magicindicator.buildins.commonnavigator.indicators.LinePagerIndicator
/**
* Created by 冯瑞雨 on 2021/7/2.
* 首页页面
*/
class
HomeFragment
:
BaseFragment
<
FragmentHomeBinding
,
HomeViewModel
>()
{
class
HomeFragment
:
BaseFragment
<
FragmentHomeBinding
,
HomeViewModel
>()
{
override
fun
initContentView
(
inflater
:
LayoutInflater
?,
container
:
ViewGroup
?,
savedInstanceState
:
Bundle
?)
=
R
.
layout
.
fragment_home
override
fun
initVariableId
()
=
BR
.
viewModel
override
fun
initData
()
{
super
.
initData
()
initTabFragment
()
}
private
fun
initTabFragment
()
{
val
tabNames
=
mutableListOf
<
String
>()
tabNames
.
add
(
"热门"
)
tabNames
.
add
(
"变老特效"
)
tabNames
.
add
(
"变年轻特效"
)
tabNames
.
add
(
"老照片修复"
)
tabNames
.
add
(
"黑白照片上色"
)
val
fragments
=
mutableListOf
<
Fragment
>()
fragments
.
add
(
MyFragment
())
fragments
.
add
(
MyFragment
())
fragments
.
add
(
MyFragment
())
fragments
.
add
(
MyFragment
())
fragments
.
add
(
MyFragment
())
//初始化viewpager2
binding
.
viewPager
.
init
(
this
,
fragments
)
//初始化 magic_indicator
binding
.
magicIndicator
.
bindViewPager2
(
binding
.
viewPager
,
tabNames
,
{},
20f
,
true
)
}
private
fun
ViewPager2
.
init
(
fragment
:
Fragment
,
fragments
:
List
<
Fragment
>,
isUserInputEnabled
:
Boolean
=
true
):
ViewPager2
{
//是否可滑动
this
.
isUserInputEnabled
=
isUserInputEnabled
//设置适配器
adapter
=
object
:
FragmentStateAdapter
(
fragment
)
{
override
fun
createFragment
(
position
:
Int
)
=
fragments
[
position
]
override
fun
getItemCount
()
=
fragments
.
size
}
return
this
}
private
fun
MagicIndicator
.
bindViewPager2
(
viewPager
:
ViewPager2
,
mStringList
:
List
<
String
>
=
arrayListOf
(),
action
:
(
index
:
Int
)
->
Unit
=
{},
mTextSize
:
Float
=
18f
,
isBold
:
Boolean
=
false
)
{
val
commonNavigator
=
CommonNavigator
(
Utils
.
getContext
())
commonNavigator
.
adapter
=
object
:
CommonNavigatorAdapter
()
{
override
fun
getCount
():
Int
{
return
mStringList
.
size
}
override
fun
getTitleView
(
context
:
Context
,
index
:
Int
):
IPagerTitleView
{
return
ScaleTransitionPagerTitleView
(
Utils
.
getContext
()).
apply
{
//设置文本
text
=
mStringList
[
index
]
//字体大小
textSize
=
mTextSize
// 加粗
typeface
=
if
(
isBold
)
Typeface
.
defaultFromStyle
(
Typeface
.
BOLD
)
else
Typeface
.
defaultFromStyle
(
Typeface
.
NORMAL
)
//未选中颜色
normalColor
=
Color
.
BLACK
//选中颜色
selectedColor
=
ContextCompat
.
getColor
(
context
,
R
.
color
.
main_color
)
//点击事件
setOnClickListener
{
viewPager
.
currentItem
=
index
action
.
invoke
(
index
)
}
}
}
override
fun
getIndicator
(
context
:
Context
):
IPagerIndicator
{
return
LinePagerIndicator
(
context
).
apply
{
mode
=
LinePagerIndicator
.
MODE_EXACTLY
//线条的宽高度
lineHeight
=
UIUtil
.
dip2px
(
Utils
.
getContext
(),
3.0
).
toFloat
()
lineWidth
=
UIUtil
.
dip2px
(
Utils
.
getContext
(),
30.0
).
toFloat
()
//线条的圆角
roundRadius
=
UIUtil
.
dip2px
(
Utils
.
getContext
(),
6.0
).
toFloat
()
startInterpolator
=
AccelerateInterpolator
()
endInterpolator
=
DecelerateInterpolator
(
2.0f
)
//线条的颜色
setColors
(
ContextCompat
.
getColor
(
context
,
R
.
color
.
main_color
))
}
}
}
this
.
navigator
=
commonNavigator
viewPager
.
registerOnPageChangeCallback
(
object
:
ViewPager2
.
OnPageChangeCallback
()
{
override
fun
onPageSelected
(
position
:
Int
)
{
super
.
onPageSelected
(
position
)
this
@bindViewPager2
.
onPageSelected
(
position
)
action
.
invoke
(
position
)
}
override
fun
onPageScrolled
(
position
:
Int
,
positionOffset
:
Float
,
positionOffsetPixels
:
Int
)
{
super
.
onPageScrolled
(
position
,
positionOffset
,
positionOffsetPixels
)
this
@bindViewPager2
.
onPageScrolled
(
position
,
positionOffset
,
positionOffsetPixels
)
}
override
fun
onPageScrollStateChanged
(
state
:
Int
)
{
super
.
onPageScrollStateChanged
(
state
)
this
@bindViewPager2
.
onPageScrollStateChanged
(
state
)
}
})
}
}
\ No newline at end of file
app/src/main/res/layout/fragment_home.xml
View file @
e0fb1ad6
...
...
@@ -5,18 +5,21 @@
name=
"ViewModel"
type=
"com.mints.goodnews.main.home.HomeViewModel"
/>
</data>
<
androidx.constraintlayout.widget.Constraint
Layout
xmlns:android=
"http://schemas.android.com/apk/res/android"
<
Linear
Layout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
<TextView
android:layout_height=
"match_parent"
android:orientation=
"vertical"
>
<net.lucode.hackware.magicindicator.MagicIndicator
android:id=
"@+id/magic_indicator"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
app:layout_constraintTop_toTopOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
android:text=
"首页"
android:textColor=
"@color/black"
android:textSize=
"39dp"
/>
android:layout_height=
"46dp"
android:layout_gravity=
"center"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.viewpager2.widget.ViewPager2
android:id=
"@+id/view_pager"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
/>
</LinearLayout>
</layout>
\ No newline at end of file
app/src/main/res/layout/home_tab_item.xml
0 → 100644
View file @
e0fb1ad6
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.AppCompatTextView
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:textSize=
"15sp"
android:singleLine=
"true"
android:gravity=
"center_horizontal"
android:textColor=
"@color/main_color"
>
</androidx.appcompat.widget.AppCompatTextView>
\ No newline at end of file
config.gradle
View file @
e0fb1ad6
...
...
@@ -99,7 +99,9 @@ ext {
//"jsbridge" : 'com.jeme:tbsjsbridge:1.1.0',
//瓦力渠道包
"walle"
:
'com.meituan.android.walle:library:1.1.6'
,
'viewpager2'
:
"androidx.viewpager2:viewpager2:1.0.0"
'viewpager2'
:
"androidx.viewpager2:viewpager2:1.0.0"
,
//指示器库
'hackware1993'
:
"com.github.hackware1993:MagicIndicator:1.7.0"
]
boolean
flutterEnable
=
false
...
...
library_base/build.gradle
View file @
e0fb1ad6
...
...
@@ -45,6 +45,8 @@ dependencies {
//阿里路由框架
api
rootProject
.
ext
.
dependencies
[
"arouter-api"
]
//指示器
api
rootProject
.
ext
.
dependencies
[
"hackware1993"
]
api
'androidx.multidex:multidex:2.0.1'
...
...
library_base/src/main/java/com/fry/base/widget/ScaleTransitionPagerTitleView.kt
0 → 100644
View file @
e0fb1ad6
package
com.fry.base.widget
import
android.content.Context
import
net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.ColorTransitionPagerTitleView
/**
* 带颜色渐变和缩放的指示器标题
* 博客: http://hackware.lucode.net
* Created by hackware on 2016/6/26.
*/
class
ScaleTransitionPagerTitleView
(
context
:
Context
)
:
ColorTransitionPagerTitleView
(
context
)
{
var
minScale
=
0.7f
override
fun
onEnter
(
index
:
Int
,
totalCount
:
Int
,
enterPercent
:
Float
,
leftToRight
:
Boolean
)
{
super
.
onEnter
(
index
,
totalCount
,
enterPercent
,
leftToRight
)
// 实现颜色渐变
scaleX
=
minScale
+
(
1.0f
-
minScale
)
*
enterPercent
scaleY
=
minScale
+
(
1.0f
-
minScale
)
*
enterPercent
}
override
fun
onLeave
(
index
:
Int
,
totalCount
:
Int
,
leavePercent
:
Float
,
leftToRight
:
Boolean
)
{
super
.
onLeave
(
index
,
totalCount
,
leavePercent
,
leftToRight
)
// 实现颜色渐变
scaleX
=
1.0f
+
(
minScale
-
1.0f
)
*
leavePercent
scaleY
=
1.0f
+
(
minScale
-
1.0f
)
*
leavePercent
}
}
library_base/version.properties
View file @
e0fb1ad6
#Mon Jul 05 1
1:22:44
CST 2021
VERSION_BUILD
=
25
50
#Mon Jul 05 1
5:08:59
CST 2021
VERSION_BUILD
=
25
61
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment