通过按钮设计支持多种屏幕尺寸

时间:2013-08-12 17:12:08

标签: android button photoshop

我在Photoshop中创建了一个按钮。问题是,当我从大屏幕手机测试应用程序时一切都很好,但是当我在较小的手机中测试时,按钮非常大。如何为每种手机尺寸制作好的尺寸按钮?

1 个答案:

答案 0 :(得分:1)

我想“我在Photoshop中设计了一个按钮”,你的意思是你设计了它的背景图像。

按钮的大小实际上不一定取决于背景图像的大小。您可以通过可在layout.xml文件(或代码中)中设置的属性来控制按钮的大小。

在这个简单的例子中,Button总是会使用父布局宽度的一半(LinearLyout)。 (观看“weightSum”和“weight”属性)。

<LinearLayout
    android:id="@+id/linearLayout1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:gravity="center_horizontal"
    android:weightSum="2">

    <Button
        android:id="@+id/btn1"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:text="Button"
        android:layout_weight="1" />

</LinearLayout> 

当然,如何根据不同的屏幕尺寸调整布局还有很多方法和属性,这应该只是给你一个简单的例子来说明它是如何完成的。 有关更多信息,请参阅Google-Android-Developer页面中的本教程:

支持多种屏幕尺寸(特别是密度 - 独立性应该对您有意义)

  

http://developer.android.com/guide/practices/screens_support.html

相关问题