如何修复标签布局中的图标

Zeeshan Shabbir

我正在尝试在选项卡布局中将图标放置在文本的左侧。到目前为止,我已经完成了,但是对齐是有问题的。可以帮助我如何对齐它们,以使文本溢出。这是它的样子在此处输入图片说明

我想这样对齐图标和文本

在此处输入图片说明

如何解决这个问题?帮助

这是我正在使用的代码和xml

tab.xml

<?xml version="1.0" encoding="utf-8"?>
<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:layout_marginTop="10dp"
android:textColor="#fff" />

这是java代码

TextView tabOne = (TextView) LayoutInflater.from(this).inflate(R.layout.tab, null);
        tabOne.setText("Dashboard");
        tabOne.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_action_action_account_balance, 0, 0, 0);
        tabLayout.getTabAt(0).setCustomView(tabOne);

        TextView tabTwo = (TextView) LayoutInflater.from(this).inflate(R.layout.tab, null);
        tabTwo.setText("Nearby");
        tabTwo.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_action_action_account_balance, 0, 0, 0);
        tabLayout.getTabAt(1).setCustomView(tabTwo);

        TextView tabThree = (TextView) LayoutInflater.from(this).inflate(R.layout.tab, null);
        tabThree.setText("Explore");
        tabThree.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_action_action_account_balance, 0, 0, 0);
        tabLayout.getTabAt(2).setCustomView(tabThree);

这是整个xml文件

<?xml version="1.0" encoding="utf-8"?>

<android.support.design.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">


    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <include
            android:id="@+id/toolbar"
            layout="@layout/toolbar"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"

            app:tabGravity="fill"
            app:tabIndicatorColor="@color/colorAccent"
            app:tabMode="fixed"

            app:tabTextColor="#fff"></android.support.design.widget.TabLayout>
    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/viewPager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/tab"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

    </android.support.v4.view.ViewPager>
</android.support.design.widget.CoordinatorLayout>

<android.support.design.widget.NavigationView
    android:id="@+id/navigation"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    app:headerLayout="@layout/consumer_header"
    android:layout_gravity="start">

</android.support.design.widget.NavigationView>

尼基尔

尝试以下 layout

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tab"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="CENTER_VERTICAL|LEFT"
android:textSize="14sp"
android:textColor="#fff" />

如果静止文本不能排成一行或它太小,则可能需要使用 textSize

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章