单击选项卡布局根本不起作用 [英] click on tab layout doesn't work at all
本文介绍了单击选项卡布局根本不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经实现了此示例.
,但无法单击第二个选项卡.
but not able to click on 2nd tab.
我的xml文件看起来像
my xml file looks like
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/header"
android:orientation="horizontal">
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="fill_parent"
android:layout_height="48dp"
android:layout_below="@+id/header"
android:background="@color/colorPrimary"
app:tabSelectedTextColor="#ffffff" />
<android.support.v4.view.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_marginTop="@dimen/padding"
android:layout_height="wrap_content"
android:layout_below="@id/tab_layout" />
</LinearLayout>
和主要活动
pager= (ViewPager) findViewById(R.id.view_pager);
tabLayout= (TabLayout) findViewById(R.id.tab_layout);
FragmentManager manager=getSupportFragmentManager();
BuyCurrencyPagerAdapter adapter=new BuyCurrencyPagerAdapter(manager);
//set Adapter to view pager
pager.setAdapter(adapter);
tabLayout.setupWithViewPager(pager);
pager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
tabLayout.setTabsFromPagerAdapter(adapter);
请提出任何建议.
推荐答案
有时候,我相信问题可能出在ViewPager位于TabLayout上方.您要像这样将其放置在下面:
Sometimes I believe the problem might be that the ViewPager is positioned above the TabLayout. You want to place it below like this:
<AppBarLayout>
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/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"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"/>
这篇关于单击选项卡布局根本不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文