Android Studio - 发出调整大小按钮的问题

时间:2016-10-15 06:41:34

标签: android xml android-studio button

出于某种原因,我无法使用手柄手动调整设计视图上的任何按钮。我可以点击并拖动手柄,但是当我发布时,在任何地方都看不到任何变化。

我使用相对布局。

以下是我尝试调整大小的其中一个按钮的xml:

<Button
    android:text="√"
    android:id="@+id/button15"
    android:background="@drawable/operator_style"
    android:textAllCaps="false"
    android:fontFamily="sans-serif"
    android:textSize="24sp"
    android:textColor="#707070"
    android:layout_alignBaseline="@+id/buttonLog"
    android:layout_alignBottom="@+id/buttonLog"
    android:layout_alignStart="@+id/button8"
    android:elevation="0dp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

按钮的样式和格式(operator_style)的xml:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:state_pressed="true" >
    <shape>
        <solid
            android:color="#00C7FC" />
        <stroke
            android:width="4dp"
            android:color="#9FEDFF" />
        <corners
            android:radius="0dp" />
    </shape>
</item>
<item>
    <shape>
        <solid
            android:color="#cccccc" />
        <corners
            android:radius="0dp" />
        <elevation
            android:elevation="2dp" />
    </shape>
  </item>
</selector>

1 个答案:

答案 0 :(得分:1)

在android中设计布局并不像你想象的那么容易,因为每个Android设备都有不同的大小。所以一切都是相互的。您可以强制按钮为特定大小(以像素为单位),但在较大屏幕上运行应用程序时,此大小将保持完全相同的像素。您可以通过转到按钮的属性并填充100px而不是wrap_content或match_parent作为宽度来实现此目的。我不建议这样做,尝试使用线性布局和其他容器。

使用线性布局并将所需的所有按钮放在此中。然后设置每个按钮的重量以设置相对于彼此的大小。如果你只需要一个按钮,只需添加一个framelayout,你可以尝试一些重量的东西。

相关问题