0
我創建了一個帶有5個選項卡的TabLayout。我想創建一個像舊Instagram一樣的菜單。所以對於第三個標籤,我需要自定義視圖,所以我會有不同的背景顏色。 我所做的到現在爲止是這樣的:Android自定義選項卡沒有得到正確的尺寸
View view1 = getLayoutInflater().inflate(R.layout.custom_tab, null);
view1.findViewById(R.id.icon).setBackgroundResource(R.drawable.profile_btn);
tabLayout.addTab(tabLayout.newTab().setIcon(R.drawable.home_btn));
tabLayout.addTab(tabLayout.newTab().setIcon(R.drawable.tools_btn));
tabLayout.addTab(tabLayout.newTab().setCustomView(view1));
tabLayout.addTab(tabLayout.newTab().setIcon(R.drawable.countdown_btn));
tabLayout.addTab(tabLayout.newTab().setIcon(R.drawable.user_btn));
但是我沒有預期的結果。這就是我的意思: 正如你所看到的,我想要的背景顏色並不能填充特定選項卡的所有寬度。 TabLayout Custom Tab
Custom_tab.xml文件使用RelativeLayout的,在這裏我設置背景色,這在它具有:
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/icon"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:layout_centerInParent="true"/>
我的朋友,我只是做了這個,但我沒有得到預期的結果:/ –