android文本中心对称,android – 约束布局按钮文本中心对齐

It’s a little bit to the right.

我认为保证金正在引起这些.根据我的经验,它不仅影响按钮.保证金也在拧紧TextInputEditText.

下面是一个工作代码,但请注意按钮上的android:layout_width =“match_parent”.任何时候我在编辑器中单击它,它将更改为android:layout_width =“0dp”,并破坏按钮对齐.

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

android:id="@+id/activity_main"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".MainActivity">

android:id="@+id/button_survey"

android:layout_width="match_parent"

android:layout_height="52dp"

android:text="Button"

app:layout_constraintBottom_toBottomOf="@+id/activity_main"

app:layout_constraintLeft_toLeftOf="@+id/activity_main"

app:layout_constraintRight_toRightOf="@+id/activity_main"

app:layout_constraintTop_toTopOf="@+id/activity_main"

tools:text="@string/main_activity_btn_survey"

android:layout_marginEnd="8dp"

android:layout_marginRight="8dp"

android:layout_marginStart="8dp"

android:layout_marginLeft="8dp" />

受Hobo joe解决方案的启发,下面是我喜欢的方式.他的解决方案正在解决,但仍需要使用填充来创建间距.如果使用了margin,则按钮文本的对齐方式将略微向右移动.所以我在LinearLayout(或ConstraintLayout)上使用填充而不是按钮上的边距.

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

xmlns:app="http://schemas.android.com/apk/res-auto"

android:id="@+id/activity_main"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".MainActivity">

android:orientation="horizontal"

android:layout_width="match_parent"

android:layout_height="wrap_content"

app:layout_constraintLeft_toLeftOf="@+id/activity_main"

app:layout_constraintTop_toTopOf="@+id/activity_main"

app:layout_constraintRight_toRightOf="@+id/activity_main"

app:layout_constraintBottom_toBottomOf="@+id/activity_main"

android:padding="16dp">

android:text="Button"

android:layout_width="match_parent"

android:layout_height="52dp"

android:id="@+id/button_survey"

android:layout_weight="1"

tools:text="@string/main_activity_btn_survey"

/>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值