【问题标题】:Android button text not aligned properlyAndroid 按钮文本未正确对齐
【发布时间】:2017-03-24 15:02:38
【问题描述】:

我有一个按钮,即使文本以布局预览为中心,当我运行应用程序时它也会向下滑动。对可能发生的事情有任何想法。

按钮 XML

<Button
    android:id="@+id/increment_setup_activity"
    android:layout_width="131dp"
    android:layout_height="59dp"
    android:background="@drawable/settings_panel"
    android:text="+"
    android:gravity="center"
    android:textColor="@color/soft_color"
    android:textSize="50sp"
    android:layout_marginTop="8dp"
    app:layout_constraintTop_toBottomOf="@+id/constraintLayout3"
    android:layout_marginRight="0dp"
    app:layout_constraintRight_toRightOf="@+id/

Android Studio 布局预览

在我的手机上运行

【问题讨论】:

  • 尝试减小字体大小,看看是否居中
  • 这确实是问题所在,我看到了这篇文章,并且在发布这个问题之前我确实改变了文字,但它仍然没有居中。在再次找到帖子的链接后——这次是你——我决定做一个更极端的减少,它工作正常。我不确定是否应该标记我的问题或将其留在这里。尽管如此,还是非常感谢您并为您点赞。
  • caiomcg 我会添加答案请采纳

标签: java android


【解决方案1】:

因为你有一个更大的字体大小中心对齐文本(默认在按钮上)不起作用尝试减小字体大小更多信息visit this stackoverflow answer

【讨论】:

    【解决方案2】:

    添加它:

      <LinearLayout android:layout_width="match_parent" 
                      android:id="@+id/linearLayout1"  
                      android:gravity="center"
                      >
    

    在此处添加您的组件和按钮

    </LinearLayout>
    

    【讨论】:

      猜你喜欢
      • 2022-12-04
      • 2020-01-15
      • 1970-01-01
      • 2016-04-04
      • 1970-01-01
      • 2013-11-11
      • 2014-06-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多