我使用来自astuetz的PagerSlidingTabStrip,并在选择器中使用图标。我有两个片段。选项卡条在xml中定义:
<com.astuetz.PagerSlidingTabStrip
android:id="@+id/ptsOverview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
psts:pstsShouldExpand="true"
psts:pstsIndicatorHeight="5dp"
psts:pstsDividerColor="#FFFFFF"
psts:pstsIndicatorColor="@color/pts_indicator"/>问题是我找不到正确的图标大小。如果尺寸太大,图标将显示为中心裁剪。如果图标太小,则显示错误。
知道图标的正确大小是多少吗?谢谢
发布于 2015-12-10 22:17:44
好吧,我想我至少找到了一种“修改”标签图标的方法。
在239行
private void addIconTab(final int position, int resId) {
ImageButton tab = new ImageButton(getContext());
tab.setImageResource(resId);
addTab(position, tab);
}你可以看到他使用了一个ImageButton来滑动视图,所以从这里:What's the default ScaleType of ImageView?它说
默认按钮的值是FIT_CENTER,但ScaleType的值是"fitXY“
因此,图标现在被拉长以适应X和Y。如果您将此行添加到您想要的任意位置:
tab.setScaleType(ImageView.ScaleType.FIT_START);或
tab.setScaleType(ImageView.ScaleType.CENTER_INSIDE);你可以得到一些更好的结果。最后找到一个适合你的解决方案..
当然,您必须将PagerSlidingTabStrip项目作为依赖项包含在android studio的.gradle配置文件中。
https://stackoverflow.com/questions/28984092
复制相似问题