1

https://github.com/google/iosched/blob/master/android/src/main/java/com/google/samples/apps/iosched/ui/widget/SlidingTabLayout.javaタブクラスを使用しています。

プロジェクトに適用した後、 この図に示すように (中央に配置されていない) タブが表示されますが、 Play Marketタブのようにタブを中央に配置したいと考えています。

Google Play アプリのようにタブを中央に配置するにはどうすればよいですか?

4

3 に答える 3

0

方法を変更してscrollToTab、選択したタブを中央に配置します。

private void scrollToTab(int tabIndex, int positionOffset) {
    final int tabStripChildCount = mTabStrip.getChildCount();
    if (tabStripChildCount == 0 || tabIndex < 0 || tabIndex >= tabStripChildCount) {
        return;
    }

    View selectedChild = mTabStrip.getChildAt(tabIndex);
    if (selectedChild != null) {
        int viewWidth = getWidth();
        int tabWidth = selectedChild.getWidth();
        int tabPosition = selectedChild.getLeft() + positionOffset;
        int targetScrollX = tabPosition - viewWidth / 2 + tabWidth / 2;

        scrollTo(targetScrollX, 0);
    }
}
于 2015-02-28T20:12:13.683 に答える
0

activity_main.xmlファイルは次のようになります

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity">

<samples.exoguru.materialtabs.SlidingTabLayout
    android:id="@+id/tabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:elevation="2dp"
    android:background="@color/ColorPrimary"/>

<android.support.v4.view.ViewPager
    android:id="@+id/pager"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:layout_weight="1">
</android.support.v4.view.ViewPager>

うまくいかなかった可能性のあるものは他に何も知りません。

ここに画像の説明を入力

于 2015-02-28T23:04:06.160 に答える