0

使用这些图像:

在此处输入图像描述 (333x300) 在此处输入图像描述 (1680x1050)

这个布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="12dp"
    android:orientation="vertical">

    <LinearLayout 
        android:orientation="horizontal"
        android:layout_width="match_parent" 
        android:layout_height="0dp"
        android:layout_weight="1"
        android:gravity="center">    

        <ImageButton
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:scaleType="fitCenter"
            android:src="@drawable/apple" />

        <ImageButton
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:scaleType="fitCenter"
            android:src="@drawable/apple" />
    </LinearLayout>

    <LinearLayout 
        android:orientation="horizontal"
        android:layout_width="match_parent" 
        android:layout_height="0dp"
        android:layout_weight="1"
        android:gravity="center">   

        <ImageButton
            style="@style/OtherButton"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:scaleType="fitCenter"
            android:src="@drawable/orange" />

        <ImageButton
            style="@style/OtherButton"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:scaleType="fitCenter"
            android:src="@drawable/orange" />

    </LinearLayout>
</LinearLayout>

给出这个结果:

在此处输入图像描述

只有单嵌套布局,苹果和橙色按钮的大小相同。在使用 Eclipse 之后,我注意到按钮在图像较大时往往会更高,但相对比例似乎并没有遵循特定的模式。

为什么按钮有不同的高度?我可以使用另一种方法来缩放屏幕分辨率和密度吗?

4

1 回答 1

1

进行以下更改。

在您的主要父布局中,将 layout_height 设置为android:layout_height="fill_parent"

于 2012-12-31T05:43:06.430 回答