Android TabPage Indicator 内容包装问题

标签 android android-viewpager tabpage indicator viewpagerindicator

我遇到了 ViewPager 的另一个问题,我现在无法用我目前的知识解决它。

我有带 ViewPager 的 TabPageIndicator,在每个选项卡上,我都显示文本。这是简单的 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>

我希望选项卡中的文本始终是单行并且始终是整个文本,而不是椭圆形、无换行、不超过 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);
    }
 }

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);
//          }
        }

现在它按我想要的方式工作...我一直在看错误的代码部分。

关于Android TabPage Indicator 内容包装问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11242421/

相关文章:

java - 我如何才能防止 LogCat 接收到我手机上的所有内容?

android - 删除 App Logo 旁边的空白区域(ActionBar Sherlock)

android - 如何在一次显示多个 fragment 的同时在 viewpager 中查找当前可见的 fragment

c# - 激活 TabControl 的 TabPage

java - Android 并在剩余可用堆空间的情况下运行 OOM

android - SharedPreferences 应用程序上下文与 Activity 上下文

android - 在 ViewPager android 的中心对齐 subview

android - 使用 viewpager 实现滑动抽屉,其中滑动抽屉驻留在 viewpager 上

vb.net - 以编程方式隐藏/删除 VB.NET 中的标签页

c# - 在 C# 中使用 Windows 窗体隐藏/阻止选项卡