-1
我試圖將圖標放在選項卡布局中文本的左側。迄今爲止我已經做到了,但是對齊是問題。有些可以幫助我如何對齊,以便文本溢出。這裏是如何尋找 如何修復選項卡布局中的圖標
我要對齊圖標和文本彼此這樣
如何解決這一問題?幫助
這裏是代碼和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>
發揮它修復了對齊問題,但儀表板的文本分成兩行 –
@ZeeshanShabbir減少'textSize'使它成爲'12sp'並嘗試 – Nikhil
這將減少文本大小兄弟:( –