【问题标题】:How to make a steady button irrespective to screen size无论屏幕大小如何制作稳定的按钮
【发布时间】:2015-10-03 22:25:05
【问题描述】:

如何在android studio中让app Button稳定在原位,不随设备屏幕尺寸移动或改变位置?

<Button
    android:layout_width="120dp"
    android:layout_height="70dp"
    android:text="START ENGINE"
    android:id="@+id/play"
    android:textSize="25sp"
    android:textColor="#ffffffff"
    android:layout_marginLeft="88dp"
    android:layout_marginStart="88dp"
    android:background="#ffb55b19"
    android:onClick="startup"
    android:layout_marginBottom="198dp"
    android:layout_gravity="right|top|center|bottom"
    android:clickable="false"
    android:focusable="false"
    android:enabled="false"
    android:focusableInTouchMode="false"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:gravity="center_horizontal" />

【问题讨论】:

  • 取决于您在屏幕上还有哪些其他资产。还有你正在使用什么布局类型。 IE。相对、线性等
  • 我使用相对布局而不是线性布局,当我在模拟器中从纵向模式更改为横向时,按钮的位置会发生变化,那么我该怎么做才能避免这种情况?

标签: android android-view android-button


【解决方案1】:

当涉及到相对布局时,有一些选项可用于垂直和水平居中。像这样。

     <Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:text="Button" />

【讨论】:

  • 我想摆脱所有 align 废话和 margin 废话并做 layout_center。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-26
  • 2018-01-20
  • 2016-05-17
  • 1970-01-01
  • 2023-03-22
  • 2017-12-02
相关资源
最近更新 更多