Android 创建在所有屏幕上看起来完美的按钮

Android 创建在所有屏幕上看起来完美的按钮,android,button,Android,Button,在android的表格布局中,我在屏幕底部有五个按钮。 我想在android的所有屏幕上都显示相同的按钮(高度应该是合适的),下面是footer的xml文件中的代码,但问题是htc one和三星s4中的按钮高度看起来很长。如何解决这个问题 <TableLayout android:id="@+id/tableLayout1" android:layout_width="fill_parent" android:layout_height="

在android的表格布局中,我在屏幕底部有五个按钮。 我想在android的所有屏幕上都显示相同的按钮(高度应该是合适的),下面是footer的xml文件中的代码,但问题是htc one和三星s4中的按钮高度看起来很长。如何解决这个问题

 <TableLayout
        android:id="@+id/tableLayout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:orientation="horizontal"
        android:background="#3F689C"
        android:weightSum="5" >

        <TableRow
            android:id="@+id/tableRow1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="horizontal" >

            <Button
                android:id="@+id/btn_home"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:background="@drawable/home" />

            <Button
                android:id="@+id/btn_contact_us"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:background="@drawable/contact_us_1" />

            <Button
                android:id="@+id/btn_about_us"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:background="@drawable/about_us_1" />

            <Button
                android:id="@+id/btn_notification"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:background="@drawable/notification" />

            <Button
                android:id="@+id/btn_setting"
                android:layout_width="wrap_content"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:background="@drawable/setting" />
        </TableRow>
        </TableLayout>

试试这个。您需要将布局作为相对布局的子级

<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/menu_layout" >

        <android.support.v4.view.PagerTabStrip
            android:id="@+id/interactive_title_tabs"
            style="@style/PagerTitleStrip"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="top" />
    </android.support.v4.view.ViewPager>

    <LinearLayout
        android:id="@id/menu_layout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="@color/grey_menu_backgroud"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/send_data_menu_button"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/custom_menu_button"
            android:text="@string/send_data" />

        <Button
            android:id="@+id/sync_menu_button"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/custom_menu_button"
            android:text="@string/check_for_cmd" />

        <Button
            android:id="@+id/apps_menu_button"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/custom_menu_button"
            android:text="@string/app_store" />
    </LinearLayout>

</RelativeLayout>

我认为您需要的是创建支持多种屏幕大小的按钮

请通过提供足够信息的链接

通常android设备屏幕分为四类

xlarge屏幕至少为960dp x 720dp

大屏幕至少为640dp x 480dp

正常屏幕至少为470dp x 320dp

小屏幕至少为426dp x 320dp

因此,如果你想设计你的应用程序来支持所有这些屏幕尺寸,那么你需要四个独立的布局文件

就是

res/layout/my_layout.xml             // layout for normal screen size ("default")

res/layout-small/my_layout.xml       // layout for small screen size

res/layout-large/my_layout.xml       // layout for large screen size

res/layout-xlarge/my_layout.xml      // layout for extra large screen size

res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation
您可以为不同的屏幕提供不同的宽度和高度

android系统将自动选择合适的布局


希望有帮助。

使用9-patch图像,这样您就可以调整图像中唯一将拉伸或不拉伸的区域。 请查看此处以了解更多信息。

按钮大小显然会根据屏幕大小而拉伸,因为您已将宽度设置为
wrap\u content
,将高度设置为
fill\u parent
。那么@Girish Gowda的解决方案是什么?请将您的代码发布在此处,此粘贴箱可能会被删除。我尝试发布完整代码,但只占用了部分代码。我粘贴了它,并在其中使用了代码标签,但它不起作用。你能帮我吗?好的。由于某种原因,它不能更早地工作。