TabLayout tabItem tabGravity center无法正常工作

时间:2017-08-29 06:27:47

标签: android xml android-tablayout

它可以正常工作超过5个标签但是当3个标签看起来不那么好时 这是我的TabLayout XML代码:

 <android.support.design.widget.TabLayout
            android:gravity="center"
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/search_bar"
            android:fillViewport="false"
            app:tabGravity="center"
            app:tabIndicatorColor="@color/ThemeColor"
            app:tabIndicatorHeight="6dp"
            app:tabMode="scrollable"
            android:paddingBottom="2dp"
            android:background="@drawable/bottom_dotted_border"
            app:tabSelectedTextColor="@color/ThemeColor"
            app:tabTextAppearance="@style/TabLayoutTextStyle"
            app:tabTextColor="@color/White" />

problamatic tab desire tab

2 个答案:

答案 0 :(得分:1)

只需将此 import UIKit import Firebase class ViewController: UIViewController { @IBOutlet weak var emailTextField: UITextField! @IBOutlet weak var pwordTxtField: UITextField! @IBOutlet weak var continuebutton: UIButton! override func viewDidLoad() { super.viewDidLoad() } @IBAction func button(_ sender: Any) { let email = emailTextField.text let password = pwordTextField.text Auth.auth().createUser(withEmail: email! , password: password!, completion: { (user, error) in if let error = error { print(error.localizedDescription) } else { print("Success") } }) } } 更改为 app:tabMode="scrollable" 在您的标签布局中

  

<强> 1。 app:tabMode =“fixed :标签在标签布局中得到修复(当标签有长标题时不适用)

     

<强> 2。 tabMode:scrollable - 当标签有长长的标题时,您可以水平滚动标签

示例代码

app:tabMode="fixed"

答案 1 :(得分:0)

如果您使用 tabMode:scrollable,只需将 android:layout_width="match_parent" 修正为 "wrap_content"