3 回答

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);
}
讓我知道更多查詢。}

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>
添加回答
舉報