简体   繁体   English

带有小图标的ANDROID TabLayout

[英]ANDROID TabLayout with small icons

I want to use tabLayout using only icons - 我想只使用图标使用tabLayout-

     tabLayout = (TabLayout) findViewById(R.id.tabs);
        tabLayout.addTab(tabLayout.newTab().setIcon(R.drawable.ic_undo_black_48dp));
        tabLayout.addTab(tabLayout.newTab().setIcon(R.drawable.ic_redo_black_48dp));

but the problem is the tab bar that i get shows small icons with a lot of space around it and if I use a linearLayout on imageViews it shows the right size. 但是问题是我得到的标签栏显示带有周围很大空间的小图标,如果我在imageViews上使用linearLayout,它会显示正确的大小。 在此处输入图片说明

The above one is of tabLayout and the bottom is the Linear Layout and both are using same drawables. 上面的是tabLayout,底部的是Linear Layout,两者都使用相同的drawable。 How do i fix this in TabLayout? 如何在TabLayout中解决此问题?

try this: 尝试这个:

<android.support.design.widget.TabLayout
         android:layout_height="wrap_content"
         android:layout_width="match_parent">

          <android.support.design.widget.TabItem
             android:icon="@drawable/ic_redo_black_48dp"/>

     <android.support.design.widget.TabItem
             android:icon="@drawable/ic_undo_black_48dp"/>

 </android.support.design.widget.TabLayout

or your can add your custom layout to TabItem by 或者您可以通过以下方式将自定义布局添加到TabItem

android:layout android:layout

for more detail : TabLayout and TabItem 有关更多详细信息: TabLayoutTabItem

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM