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

时间:2013-09-14 07:57:30

标签: android button

我在android的表格布局中有五个按钮位于屏幕底部。 我想在android的所有屏幕中显示所有这些按钮相同(高度应该看起来正确),以下是xml文件中的代码,但是问题是按钮高度看起来在htc one和samsung 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>

3 个答案:

答案 0 :(得分:0)

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

<?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>

答案 1 :(得分:0)

我认为你需要的是创建支持多种屏幕尺寸的按钮。

请浏览this链接,该链接可为您提供足够的信息。

通常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系统会自动选择合适的布局。

希望它有所帮助。

答案 2 :(得分:0)

使用9张图片,因此您可以调整图像的唯一区域,这些区域将被拉伸或不拉伸。 请查看此处获取更多信息。 http://developer.android.com/tools/help/draw9patch.html

相关问题