在选项卡自定义布局中,我将其父元素match_parent
设置为并设置其背景颜色.当我运行它时,标签显示自定义布局包装元素imageview和textview.我希望这个自定义布局将填充选项卡,选项卡之间没有任何空格.检查输出:
private void setupTabLayout(ViewPager viewPager, ViewPagerAdapter viewPagerAdapter) {
TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
tabLayout.setupWithViewPager(viewPager);
int length = tabLayout.getTabCount();
for (int i = 0; i < length; i++) {
tabLayout.getTabAt(i).setCustomView(viewPagerAdapter.getTabView(i));
}
}
Run Code Online (Sandbox Code Playgroud)
tab_layout.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/layout"
android:background="@color/grey_accent">
<ImageView
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/icon"
android:src="@drawable/ic_action_home"
android:layout_marginBottom="19dp"
android:layout_above="@+id/title"
android:layout_centerHorizontal="true" />
<TextView
android:layout_gravity="center"
android:textColor="@color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Home"
android:id="@+id/title"
android:layout_marginBottom="259dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
ViewPagerAdapter:
public View getTabView(int position) {
View view = LayoutInflater.from(this.context).inflate(R.layout.tab_layout, null);
TextView title = (TextView) view.findViewById(R.id.title);
ImageView icon …
Run Code Online (Sandbox Code Playgroud) android android-layout android-design-library androiddesignsupport android-tablayout
有没有办法在TabLayout中的选项卡之间添加边距?我尝试过为Widget.Design.TabLayout使用自定义样式,但是有些属性只与填充有关,但没有边距.
android ×2