【发布时间】:2020-06-14 11:37:03
【问题描述】:
我有一个可滚动的 tablayout,但是当我选择一个 tabitem 时,可滚动停止,当我选择任何一个时,我需要在中心的 TabItem。谢谢。
<com.google.android.material.tabs.TabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabSelectedTextColor="@color/colorPrimary">
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Calle Mármol complejo 23" />
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Calle Mármol complejo 23" />
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
现在是 java 文件,只是为了转到 tabitem
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
boolean fragmentTransaction = false;
Fragment fragment = null;
switch (menuItem.getItemId()) {
case R.id.nav_home:
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
new HomeFragment()).commit();
titleToolbar = getResources().getString(R.string.Menu_Home);
fragmentTransaction = true;
getSupportActionBar().setTitle(titleToolbar);
break;
case R.id.nav_receipts:
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,
new ReceiptsFragment()).commit();
titleToolbar = getResources().getString(R.string.Menu_Receipts);
fragmentTransaction = true;
getSupportActionBar().setTitle(titleToolbar);
break;
【问题讨论】: