我需要讓我的應用程序使用此外觀(圖標和文本):https://material-design.storage.googleapis.com/publish/material_v_4/material_ext_publish/0B6Okdz75tqQsbHJuWi04N0ZIc0E/components_tabs_usage_mobile7.png就像把圖標和文字放在標籤(滑動標籤)android?
但到目前爲止,我只能離開它是這樣的:http://i.imgur.com/npz0eRJ.png
我該如何解決這個問題?
按照我的XML標籤:在片段(標籤)
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
android: layout_width = "match_parent"
android: layout_height = "match_parent"
android: gravity = "center">
<ImageView
android: id = "@ + id/imgTab"
android: layout_width = "wrap_content"
android: layout_height = "wrap_content"
/>
<TextView
android: TEXTSIZE = "14sp"
android: textColor = "@ android: color/white"
android: id = "@ + id/tv_tab"
android: layout_width = "wrap_content"
android: layout_height = "wrap_content" />
</ LinearLayout>
方法:
public CharSequence getPageTitle (int position) {
Drawable tab = mContext.getResources() getDrawable (icons [position]).;
tab.setBounds (0, 0, heightIcon, heightIcon);
ImageSpan ImageSpan is = new (tab);
SpannableString sp = new SpannableString (titles [position]);
sp.setSpan (s, sp.length() - 1, sp.length(), 0);
return sp;
我試圖按照Need to center-align a single portion of text in a TextView,但它並沒有爲我工作:(
燦任何人都可以幫我嗎?
投了我的答案中的鏈接,如果你想。 – Harry