我想制作一个按钮,其中左右上边距和下边距相同。 但我得到这样的东西:
这是一个布局:
<RelativeLayout android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView android:id="@+id/people_number_label"
android:text="@string/number_of_people"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<Button
android:id="@+id/people_number"
android:layout_toRightOf="@+id/people_number_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
最佳答案
所以 Button 的工作方式是它是一个带有可绘制背景的 TextView 。那个drawable就是你看到的那个。正如您在此处看到的,文本将在该可绘制对象中居中。如果您希望文本与提示一致,则按钮不适合您。您最好将其设为 TextView 并使用圆角矩形设置可绘制的 xml 背景,使其看起来像一个按钮,但实际上并非如此。
另一件事你可以尝试做align_baseline 两个 View 。这应该对齐文本,但可能会将提示向下推到屏幕上
关于Android,意外的按钮左右填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30946587/