-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
将KDTab类改为继承FrameLayout,自定义Tab更加方便,并增加一个TextViewTab的示例
- Loading branch information
Showing
4 changed files
with
96 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
app/src/main/java/github/xuqk/kdtablayout/sample/widget/TextViewTab.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package github.xuqk.kdtablayout.sample.widget | ||
|
||
import android.annotation.SuppressLint | ||
import android.content.Context | ||
import android.graphics.Color | ||
import android.graphics.Typeface | ||
import android.view.Gravity | ||
import android.widget.FrameLayout | ||
import android.widget.TextView | ||
import github.xuqk.kdtablayout.widget.KDTab | ||
import github.xuqk.kdtablayout.widget.tab.KDColorMorphingTextTab | ||
|
||
/** | ||
* Created By:XuQK | ||
* Created Date:21-3-5 下午2:57 | ||
* Creator Email:[email protected] | ||
* Description: | ||
*/ | ||
|
||
@SuppressLint("ViewConstructor") | ||
class TextViewTab(context: Context, text: String) : KDTab(context) { | ||
|
||
private val tv: TextView = TextView(context).apply { | ||
this.text = text | ||
textSize = 16f | ||
} | ||
|
||
init { | ||
addView( | ||
tv, | ||
LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT).apply { | ||
gravity = Gravity.CENTER | ||
} | ||
) | ||
} | ||
|
||
override fun onScrolling(selectedFraction: Float, selectedInLeft: Boolean) { | ||
if (selectedFraction > 0.5f) { | ||
tv.typeface = Typeface.DEFAULT_BOLD | ||
} else { | ||
tv.typeface = Typeface.DEFAULT | ||
} | ||
} | ||
|
||
override fun reset() { | ||
tv.typeface = Typeface.DEFAULT | ||
} | ||
|
||
override fun selectTab() { | ||
tv.typeface = Typeface.DEFAULT_BOLD | ||
} | ||
|
||
override fun computeContentBounds() { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters