Haw*_*awk 9 android tabpage indicator android-viewpager viewpagerindicator
我遇到了ViewPager的另一个问题,我现在的知识无法解决它.
我有TabPageIndicator和ViewPager,在每个标签上,我都显示文字.这是简单的textView:
<?xml version="1.0" encoding="utf-8"?>
<view xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
class="viewpagerindicator.TabPageIndicator$TabView" >
<TextView
android:id="@+id/vpi_tab_text"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:singleLine="true"
android:ellipsize="marquee"
android:gravity="center"
android:paddingBottom="10dip"
android:paddingLeft="8dip"
android:paddingRight="8dip"
android:paddingTop="10dip"
android:textColor="@drawable/vpi_tab_text_color"
android:typeface="serif" />
</view>
Run Code Online (Sandbox Code Playgroud)
我希望选项卡中的文本始终是一行,并且始终是整个文本,而不是椭圆形,不包装,不超过1行.用户需要能够全部阅读...
但我不能这样做,我尝试了不同的选项,但我仍然遇到一些问题 - 文本不仅仅有一行,而且只显示第一行,或者只显示部分文本.
你有过类似的经历吗?
任何帮助表示赞赏
编辑一:
我相信问题在这里:
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
final boolean lockedExpanded = widthMode == MeasureSpec.EXACTLY;
setFillViewport(lockedExpanded);
final int childCount = mTabLayout.getChildCount();
if (childCount > 1 && (widthMode == MeasureSpec.EXACTLY || widthMode == MeasureSpec.AT_MOST)) {
if (childCount > 2) {
mMaxTabWidth = (int) (MeasureSpec.getSize(widthMeasureSpec) * 0.4f);
} else {
mMaxTabWidth = MeasureSpec.getSize(widthMeasureSpec) / 2;
}
} else {
mMaxTabWidth = -1;
}
final int oldWidth = getMeasuredWidth();
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
final int newWidth = getMeasuredWidth();
if (lockedExpanded && oldWidth != newWidth) {
// Recenter the tab display if we're at a new (scrollable) size.
setCurrentItem(mSelectedTabIndex);
}
}
Run Code Online (Sandbox Code Playgroud)
mMaxTabWidth ...
我觉得这个问题很简单,我把这部分注释掉了:
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
// Re-measure if we went beyond our maximum size.
// if (mParent.mMaxTabWidth > 0 && getMeasuredWidth() > mParent.mMaxTabWidth) {
// super.onMeasure(MeasureSpec.makeMeasureSpec(mParent.mMaxTabWidth, MeasureSpec.EXACTLY), heightMeasureSpec);
// }
}
Run Code Online (Sandbox Code Playgroud)
现在它按照我想要的方式工作......我一直在查看代码的错误部分。
| 归档时间: |
|
| 查看次数: |
3504 次 |
| 最近记录: |