gpt4 book ai didi

android - 选项卡之间的间距 TabPageIndicator

转载 作者:行者123 更新时间:2023-11-30 01:56:23 28 4
gpt4 key购买 nike

我正在尝试实现我的设计师为我设计的设计。

我无法将 compoundDrawable 移近文本(设置 padding 属性可以将其移远,但即使是 0dp 也无法使其靠近)并且我无法使标签之间的间距保持恒定宽度。

Tabs design

这是我得到的(不要看字体、文本颜色、下划线大小,目前正在开发中):

enter image description here

但我在定制 Jake's Wharton 时遇到了麻烦 library

这是几乎相同的问题:Space between elements of the indicator

<style name="SkillsPageIndicator" parent="Widget.TabPageIndicator">
<item name="android:background">@drawable/tab_underline_indicator</item>
<item name="android:textSize">@dimen/text_size_medium</item>
<item name="android:paddingTop">35dp</item>
<item name="android:paddingBottom">16dp</item>
<item name="android:drawablePadding">0dp</item>
<item name="android:gravity">center</item>
<item name="android:width">100dp</item>
</style>

最佳答案

我编写的代码不是很干净,但它对我有用。我在这里分享它以帮助任何需要它的人:

done image

更改 TabPageIndicator.addTab 中的代码:

private void addTab(int index, CharSequence text, int iconResId) {
final TabView tabView = new TabView(getContext());
tabView.mIndex = index;
tabView.setFocusable(true);
tabView.setOnClickListener(mTabClickListener);
tabView.setText(text);

/**
* My parts (CullyCross):
*/

Resources r = getResources();
DisplayMetrics metrics = r.getDisplayMetrics();
float screenWidth = metrics.widthPixels;

float width = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 100, metrics);
int margin = (int)(screenWidth - 2 * width) / 4;

LinearLayout.LayoutParams params = new LinearLayout.LayoutParams((int)width, MATCH_PARENT);
params.setMargins(margin, 0, margin, 0);


/***********************/

if (iconResId != 0) {
tabView.setCompoundDrawablesWithIntrinsicBounds(iconResId, 0, 0, 0);
}

/**
* original
* mTabLayout.addView(tabView, new LinearLayout.LayoutParams(0, MATCH_PARENT, 1));
*/

mTabLayout.addView(tabView, params);
}

使用更细的字体看起来会更好。

关于android - 选项卡之间的间距 TabPageIndicator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32148821/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com