按钮边距更改与按钮文本内容

And*_*rs8 2 xml layout android button

让我们从有趣的部分开始,这是麻烦的图形.水平,一切都很美.

沉没按钮 中间按钮,我想与其他三个对齐.以下是基础知识:

  1. 总的来说,这是一个相对的布局
  2. 在这个relativelayout里面,它是一个水平线性布局,包含三个按钮
  3. 中间按钮的"下沉"与它是双线文本100%相关,如果我将它改为单行,它会正确对齐
  4. 按钮的指定高度与下沉无关,即使是当前大小的两倍以上(从当前的70到170),也会显示完全相同的行为(和行为大小)
  5. "custom_button"背景无效,如果我将它们全部更改为无背景,库存查看按钮,则会发生相同的定位

这里是XML(只是relativelayout中的linearlayout):

<LinearLayout 
android:id="@+id/wideButtons"
android:layout_below="@+id/buttonClockFinish"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:orientation="horizontal">

    <Button
    android:id="@+id/buttonLog"
    android:layout_weight="1"
    android:layout_height="70dp"
    android:padding="0dp"
    android:layout_marginRight="3dp"
    android:layout_width="fill_parent"
    android:background="@drawable/custom_button"
    android:text="View Log" />

    <Button
    android:id="@+id/buttonLocation"
    android:layout_weight="1"
    android:layout_height="70dp"
    android:padding="0dp"
    android:layout_marginLeft="3dp"
    android:layout_marginRight="3dp"
    android:layout_width="fill_parent"
    android:background="@drawable/custom_button"
    android:text="Location\nD1-RS" />

    <Button
    android:id="@+id/buttonHelp"
    android:layout_weight="1"
    android:layout_height="70dp"
    android:padding="0dp"
    android:layout_marginLeft="3dp"
    android:layout_width="fill_parent"
    android:background="@drawable/custom_button"
    android:text="Help" />

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

那么为什么它不对齐呢?

And*_*rs8 7

我刚要发布这个问题,做了一个最后的实验.我在按钮上添加了第三行文字.这进一步推低了它.但我意识到它的共同点是中间按钮顶行的文字与两侧按钮的文本完全对齐.

所以它不是因为内部边缘有问题,无法将文本压在顶部边界上.对齐是TEXT,而不是按钮图形.一直以来,我都认为有一些谜团:填充,我没有归零,但有三行按钮文本,很高兴只有大约1dp左右的填充.

解决方案是增加

android:layout_gravity="center_vertical"
Run Code Online (Sandbox Code Playgroud)

到那个按钮.为了保持一致性,我也把它添加到其余的中.

经验教训:当你认为事情没有调整时,也许它们实际上是,但也许你正在看错了.