【问题标题】:Inline alignment title in circular custom button圆形自定义按钮中的内联对齐标题
【发布时间】:2017-09-06 12:22:11
【问题描述】:

我创建了一个简单的圆形按钮来为自定义对话框选择器创建 - 和 + 按钮。

如屏幕截图所示,-+ 稍微向下移动,而不是在自定义背景的中间。

我在drawable/circular_button.xml 中的自定义背景如下所示。

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">
    <stroke android:color="@color/colorPrimaryDark" android:width="1dp" />
    <solid android:color="@color/colorPrimary" />
    <size android:width="30sp" android:height="30sp"/>

</shape>

按钮在LinearLayout里面是这样配置的

        <Button
            android:id="@+id/decrease_one"
            android:layout_width="40sp"
            android:layout_height="40sp"
            android:layout_marginRight="20sp"
            android:background="@drawable/rounded_button"
            android:text="-"
            android:textColor="@color/white"
            android:textSize="30sp"
            android:textStyle="bold" />

在其中一篇文章中,我读到了标签minHeight,但它并没有解决我的问题。有什么想法吗?

【问题讨论】:

  • batter 使用 FlootingActionButton
  • 它为您带来更多好处而不是为您创建自定义按钮

标签: android android-layout button floating-action-button


【解决方案1】:

电池使用 FloatingActionButton 迷你

<android.support.design.widget.FloatingActionButton
    android:id="@+id/activity_my_digital_executor_fabDigitalex"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    card_view:fabSize="mini"
    card_view:srcCompat="@drawable/ic_new_plus" />

在你的应用依赖中添加'com.android.support:design:26.0.+'

【讨论】:

    【解决方案2】:

    这是因为你的 Button 的 android:textSize="30sp" 如果你设置 50sp 它会更下线, 只需将您的按钮转换为 Textviews 并设置 android:gravity="center" 也保持您的 textsize 30sp

    <TextView
                android:id="@+id/decrease_2"
                android:layout_width="40dp"
                android:layout_height="40dp"
                android:layout_marginRight="20dp"
                android:background="@drawable/rounded_button"
                android:text="+"
                android:gravity="center"
                android:textColor="@color/white"
                android:textSize="30sp"
                android:textStyle="bold" />
    

    【讨论】:

    • 应该可以,但是你会失去点击时的“突出显示”效果。
    【解决方案3】:

    如果您使用 Imageview 而不是 Textview,那么您的问题就解决了。

    【讨论】:

      猜你喜欢
      • 2012-04-10
      • 1970-01-01
      • 1970-01-01
      • 2021-02-14
      • 1970-01-01
      • 1970-01-01
      • 2011-03-31
      • 2020-07-10
      • 1970-01-01
      相关资源
      最近更新 更多