亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何實現一個 TabLayout,其中的選項卡從左或右開始,但不是居中?

如何實現一個 TabLayout,其中的選項卡從左或右開始,但不是居中?

FFIVE 2023-03-31 16:35:35
我如何實現一個TabLayout,其中選項卡從左側或右側開始,但不是從中心開始。TabLayout, 有一個屬性app:tabGravity="center", 但我怎樣才能安排我的標簽, 在一個特定的位置, 左或右?非常感謝。
查看完整描述

3 回答

?
慕容3067478

TA貢獻1773條經驗 獲得超3個贊

下面是為我工作。


選項卡將顯示在最左邊。


<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:app="http://schemas.android.com/apk/res-auto"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:orientation="vertical">


    <android.support.design.widget.AppBarLayout

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:layout_marginStart="2dp"

        android:layout_marginTop="2dp"

        app:layout_scrollFlags="scroll|enterAlways|snap">


        <android.support.design.widget.TabLayout

            android:id="@+id/tabs"

            android:layout_width="match_parent"

            android:layout_height="wrap_content"

            android:layout_margin="0dp"

            android:background="?attr/colorPrimary"

            android:elevation="6dp"

            android:minHeight="?attr/actionBarSize"

            app:tabGravity="fill"

            app:tabMode="scrollable"

            app:tabPaddingEnd="10dp"

            app:tabPaddingStart="20dp" />


    </android.support.design.widget.AppBarLayout>


    <android.support.v4.view.ViewPager

        android:id="@+id/view_pager"

        android:layout_width="match_parent"

        android:layout_height="match_parent"

        app:layout_behavior="@string/appbar_scrolling_view_behavior" />


</RelativeLayout>

MainActivity.java


public class MainActivity extends AppCompatActivity {


    //This is our tablayout

    private TabLayout tabLayout;


    //This is our viewPager

    private ViewPager viewPager;



    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);



        tabLayout = findViewById(R.id.tabs);

        viewPager = findViewById(R.id.view_pager);


        tabLayout.addTab(tabLayout.newTab().setText("Tab1"));

       // tabLayout.addTab(tabLayout.newTab().setText("Tab2"));

       // tabLayout.addTab(tabLayout.newTab().setText("tab3"));


        Pager adapter = new Pager(getSupportFragmentManager(), tabLayout.getTabCount());

        viewPager.setAdapter(adapter);


    }

讓我知道更多查詢。}


查看完整回答
反對 回復 2023-03-31
?
HUX布斯

TA貢獻1876條經驗 獲得超6個贊

這是截圖,如果可能的話,可以了解更多關于我的想法的信息。

如果可能的話,我想將“Inizio Sessione”選項卡從中間移動到左側或右側。

謝謝。

這是代碼:

? ?<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

? ? android:layout_width="match_parent"

? ? android:layout_height="match_parent"

? ? xmlns:app="http://schemas.android.com/apk/res-auto"

? ? android:orientation="vertical"

? ? xmlns:tools="http://schemas.android.com/tools"

? ? tools:context=".fragments.StartSessionContainerFragment">


? ? <android.support.design.widget.AppBarLayout

? ? ? ? android:layout_width="match_parent"

? ? ? ? android:layout_height="wrap_content"

? ? ? ? android:layout_marginStart="2dp"

? ? ? ? android:layout_marginTop="2dp"

? ? ? ? app:layout_scrollFlags="scroll|enterAlways|snap">


? ? ? ? <android.support.design.widget.TabLayout

? ? ? ? ? ? android:id="@+id/tabs"

? ? ? ? ? ? android:layout_width="match_parent"

? ? ? ? ? ? android:layout_height="wrap_content"

? ? ? ? ? ? android:elevation="6dp"

? ? ? ? ? ? android:minHeight="?attr/actionBarSize"

? ? ? ? ? ? android:layout_margin="0dp"

? ? ? ? ? ? app:tabPaddingStart="20dp"

? ? ? ? ? ? app:tabPaddingEnd="10dp"

? ? ? ? ? ? app:tabGravity="center"

? ? ? ? ? ? app:tabMode="scrollable"

? ? ? ? ? ? android:layout_gravity="left"

? ? ? ? ? ? android:background="?attr/colorPrimary" />


? ? </android.support.design.widget.AppBarLayout>


? ? <android.support.v4.view.ViewPager

? ? ? ? android:id="@+id/view_pager"

? ? ? ? android:layout_width="match_parent"

? ? ? ? android:layout_height="match_parent"

? ? ? ? app:layout_behavior="@string/appbar_scrolling_view_behavior" />


</RelativeLayout>


查看完整回答
反對 回復 2023-03-31
?
GCT1015

TA貢獻1827條經驗 獲得超4個贊

簡單的方法是您可以簡單地執行下面的代碼并將您想要的任何選項卡設置為默認選項卡;

viewPager.setCurrentItem(2);


查看完整回答
反對 回復 2023-03-31
  • 3 回答
  • 0 關注
  • 335 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號