开发者社区> 问答> 正文

如何设置平板电脑的tablayout图标大小

如何设置平板电脑的标签图标大小我做了很多研究,尝试了很多方法,但无法使其适应我的布局。手机屏幕正常,但平板电脑屏幕上的“7”“10”图标尺寸仍然非常小。

public class MainActivity extends AppCompatActivity {

private TabLayout tabLayout; private ViewPager viewPager;

@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);

viewPager = (ViewPager) findViewById(R.id.viewpager);
setupViewPager(viewPager);

tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.setupWithViewPager(viewPager);
setupTabIcons();

我以编程方式获取图标。

}

private void setupTabIcons() {

TextView tabOne = (TextView) LayoutInflater.from(this).inflate(R.layout.custom_tab, null);
tabOne.setText(R.string.Scanner);
tabOne.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_image, 0, 0);
tabLayout.getTabAt(0).setCustomView(tabOne);


TextView tabTwo = (TextView) LayoutInflater.from(this).inflate(R.layout.custom_tab, null);
tabTwo.setText(R.string.Create);
tabTwo.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.create, 0, 0);
tabLayout.getTabAt(1).setCustomView(tabTwo);

TextView tabThree = (TextView) LayoutInflater.from(this).inflate(R.layout.custom_tab, null);
tabThree.setText(R.string.History);
tabThree.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_history, 0, 0);
tabLayout.getTabAt(2).setCustomView(tabThree);

TextView tabFour = (TextView) LayoutInflater.from(this).inflate(R.layout.custom_tab, null);
tabFour.setText(R.string.Settings);
tabFour.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_settings, 0, 0);
tabLayout.getTabAt(3).setCustomView(tabFour);

} }

我的activity_main布局

<com.google.android.material.appbar.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

<com.google.android.material.tabs.TabLayout
    android:id="@+id/tabs"
    android:layout_width="match_parent"
    android:layout_height="@dimen/_45sdp"
    app:tabGravity="fill"
    app:tabMode="fixed" />

</com.google.android.material.appbar.AppBarLayout> custom_tab布局

展开
收起
小六码奴 2019-08-17 17:32:45 2147 0
1 条回答
写回答
取消 提交回答
  • 你可以使用3种方式

    第一种方法: -

    res/layout/main_activity.xml # For handsets (smaller than 600dp) res/layout-sw600dp/main_activity.xml # For 7” tablets (600dp wide and bigger) res/layout-sw720dp/main_activity.xml # For 10” tablets (720dp wide and bigger) 第二种方法:

    values/dimens.xml # For handsets (smaller than 600dp) values-sw600dp/dimens.xml # For 7” tablets (600dp wide and bigger) values-sw720dp/dimens.xml # For 10” tablets (720dp wide and bigger) 第三种方法:

    https://github.com/intuit/sdp

    2019-08-17 17:39:07
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载