0

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

<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>
4

4 回答 4

3

请在您的活动中检查此行

slidingTabLayout.setDistributeEvenly(true);

改为假

于 2015-09-25T04:46:59.927 回答
1

@Aman Verma

你的错是什么

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

SlidingTabLayout 以适应屏幕

于 2015-09-25T05:30:20.550 回答
0

您可以使用下面的代码来扩展选项卡中的文本。

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

希望能帮助到你。

于 2015-09-25T04:51:06.827 回答
0

在您的 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);

    }

}

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

于 2015-09-25T05:10:54.950 回答