就像把图标和文字标签

就像把图标和文字标签

本文介绍了就像把图标和文字标签(滑动标签)的Andr​​oid?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要让我与这个样子(图标和文本)的应用程序:https://material-design.storage.googleapis.com/publish/material_v_4/material_ext_publish/0B6Okdz75tqQsbHJuWi04N0ZIc0E/components_tabs_usage_mobile7.png

I need to make my application with this appearance (icon and text): https://material-design.storage.googleapis.com/publish/material_v_4/material_ext_publish/0B6Okdz75tqQsbHJuWi04N0ZIc0E/components_tabs_usage_mobile7.png

不过,到目前为止,我只能把它像这样: http://i.imgur.com/npz0eRJ巴纽

But so far I can only leave it like this: http://i.imgur.com/npz0eRJ.png

我该如何解决这个问题?

How can I fix this?

请我的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>

在片段方法(标签):

Method in the fragment (Tab):

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在一个TextView 以文字居中的一个部分,但它并没有为我工作:(

I tried to follow Need to center-align a single portion of text in a TextView but it did not work for me :(

任何人能帮助我吗?

推荐答案

请参阅我的回答Here并按照它正常。

See my answer Here and follow it properly.

在这里一点点的改变会做的伎俩:

A little change here will do the trick:

 Drawable image = getActivity().getResources().getDrawable(R.drawable.ic_launcher);
 image.setBounds(0, 0, image.getIntrinsicWidth(), image.getIntrinsicHeight());
 SpannableString sb = new SpannableString(" \n"+"hello");
 ImageSpan imageSpan = new ImageSpan(image, ImageSpan.ALIGN_BOTTOM);
 sb.setSpan(imageSpan, 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
 return sb;

在地方的你好用您的标题。

in place of the "hello" use your title.

希望这将有助于。

这篇关于就像把图标和文字标签(滑动标签)的Andr​​oid?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 19:33