【问题标题】:Sliding tab Layout Text splits up to two滑动选项卡布局文本最多拆分为两个
【发布时间】:2015-12-22 20:32:06
【问题描述】:

我正在使用slidingtablayout和slidingtabstrip,我有5个标签,但是有一个像RESTAURANT这样的大文本,它不完全可见..如果我将其他标签文本更改为大文本,它工作正常,甚至可以滚动..但不是第一种情况。我想要这个..但是标签上有上面的文字

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.example.rajdeepsingh.newlistview_module.Search">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:background="#ffffff"
        >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:weightSum="2"
            >

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:clickable="true"
            android:id="@+id/navbut"
            android:background="@drawable/arrow"
            android:layout_margin="5dp"

            />

        <com.example.rajdeepsingh.newlistview_module.SlidingTabLayout1
            android:id="@+id/sliding_tabs"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            />
        </LinearLayout>


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"

            >

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@drawable/roundedcorneredittext"
            android:layout_margin="16dp"
            android:drawableLeft="@drawable/search01"
            android:drawableStart="@drawable/search01"
            android:id="@+id/searchedittext"
            android:hint="Brands, Restaurant, Shops "
            android:textColorHint="#bdbdbd"
            android:typeface="serif"

            />
        </LinearLayout>

        <android.support.v4.view.ViewPager
            android:id="@+id/viewpager"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:background="@android:color/white" />


    </LinearLayout>






</LinearLayout>

【问题讨论】:

  • 发布你的 XML 代码
  • 更新修改后的代码
  • 你的 item.xml 在哪里?

标签: android slidertabs


【解决方案1】:

在您的 SlidingTabLayout1 中,只需替换以下两个方法,然后检查它。

/**
 * Create a default view to be used for mTabs. This is called if a custom tab
 * view is not set via {@link #setCustomTabView(int, int)}.
 */
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    textView.setLayoutParams(new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    TypedValue outValue = new TypedValue();
    getContext().getTheme().resolveAttribute(
            android.R.attr.selectableItemBackground, outValue, true);
    textView.setBackgroundResource(outValue.resourceId);
    textView.setAllCaps(true);

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources()
            .getDisplayMetrics().density);
    textView.setPadding(padding, padding, padding, padding);

    return textView;
}

private void populateTabStrip() {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final OnClickListener tabClickListener = new TabClickListener();

    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;
        TextView tabTitleView = null;

        if (mTabViewLayoutId != 0) {
            // If there is a custom tab view layout id set, try and inflate
            // it
            tabView = LayoutInflater.from(getContext()).inflate(
                    mTabViewLayoutId, mTabStrip, false);
            tabTitleView = (TextView) tabView
                    .findViewById(mTabViewTextViewId);
        }

        if (tabView == null) {
            tabView = createDefaultTabView(getContext());
        }

        if (tabTitleView == null && TextView.class.isInstance(tabView)) {
            tabTitleView = (TextView) tabView;
        }

        if (mDistributeEvenly) {
            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView
                    .getLayoutParams();
            lp.width = 0;
            lp.weight = 1;
        }

        tabTitleView.setText(adapter.getPageTitle(i));
        tabView.setOnClickListener(tabClickListener);
        String desc = mContentDescriptions.get(i, null);
        if (desc != null) {
            tabView.setContentDescription(desc);
        }

        mTabStrip.addView(tabView);
        if (i == mViewPager.getCurrentItem()) {
            tabView.setSelected(true);
        }

        tabTitleView.setTextColor(getResources().getColorStateList(
                R.color.selector));
        tabTitleView.setTextSize(14);

    }

}

如果此更新不能解决您的问题,请告诉我。

【讨论】:

    【解决方案2】:

    请检查您的活动中的这一行

    slidingTabLayout.setDistributeEvenly(true);
    

    改为假

    【讨论】:

      【解决方案3】:

      @Aman Verma

      你的错

      1. 首先启动您的 Imageview 标签&lt;ImageView
      2. 设置slidingTabsObj.setDistributeEvenly(false); // Yes: To make the Tabs Fixed set this true, This makes the tabs Space Evenly in Available宽度

      SlidingTabLayout to fit the screen

      【讨论】:

        【解决方案4】:

        您可以使用下面的代码来扩展标签中的文本。

        SlidingTabStrip tabs = (SlidingTabStrip)rootView.findViewById(R.id.tabs);
        tabs.setShouldExpand(true); 
        

        希望对你有帮助。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-10-28
          • 1970-01-01
          相关资源
          最近更新 更多