[英]How to set the tablayout icon size for tablets
如何設置平板電腦的選項卡圖標大小我做了很多研究,嘗試了許多方法,但是無法使其適應我的布局。 手機屏幕正常,但平板電腦屏幕上的“ 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布局
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif"
android:gravity="center_horizontal"
android:textColor="@color/custom_tabtext1"
android:textSize="@dimen/_9ssp"
/>
我認為您可以使用3種方式來支持平板電腦。
為平板電腦支持創建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)
為平板電腦支持創建3維文件的第二種方法:-
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)
將“ Sdp”庫用於平板電腦的第三種方式支持:-
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.