问题: 我似乎无法让我的 ImageButtons 出现在正确的位置或大小合适。
平台: 带有 Android API 16 的 Eclipse
问题: 我的 RelativeLayout 是 600x800,我的 ImageButtons 是 194x64,但是当我将它们放入编辑器时,它们是它们应该的两倍大。查看图片链接。
我的 XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android1="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/main_portal_bg" >
<RelativeLayout
android1:layout_width="353dp"
android1:layout_height="758dp"
android1:layout_marginLeft="115dp"
android1:layout_marginTop="29dp"
android1:background="#000000" >
</RelativeLayout>
<ImageButton
android1:id="@+id/new_customer_button_selector"
android1:layout_width="194dp"
android1:layout_height="64dp"
android1:layout_marginTop="89dp"
android1:contentDescription="@string/back_button_desc"
android1:background="@drawable/new_customer_button_selector" />
<ImageButton
android1:id="@+id/returning_customer_button_selector"
android1:layout_width="194dp"
android1:layout_height="64dp"
android1:layout_alignParentLeft="true"
android1:layout_below="@+id/new_customer_button_selector"
android1:contentDescription="@string/back_button_desc"
android1:src="@drawable/returning_customer_button_selector" />
<ImageButton
android1:id="@+id/redeem_coupon_button_selector"
android1:layout_width="194dp"
android1:layout_height="64dp"
android1:layout_alignParentLeft="true"
android1:layout_below="@+id/returning_customer_button_selector"
android1:contentDescription="@string/back_button_desc"
android1:src="@drawable/redeem_coupon_button_selector" />
<ImageButton
android1:id="@+id/info_button_selector"
android1:layout_width="194dp"
android1:layout_height="64dp"
android1:layout_alignParentLeft="true"
android1:layout_below="@+id/redeem_coupon_button_selector"
android1:contentDescription="@string/back_button_desc"
android1:src="@drawable/info_button_selector" />
</RelativeLayout>
研究: 我尝试使用 FitXY 的 ScaleType,设置 MaxHeight 和 MinHeight,并使用 android:background 而不是 android:src。我能够使它们变小的唯一方法是使用图形编辑器通过按住 SHIFT 并拖动右下角来调整它们的大小。不幸的是,这也迫使它们自动对齐到布局的底部,当我尝试移动它们时,它们会弹回到原来的大小,所有其他按钮都会在布局周围移动。编辑 XML 只是完成了一部分。
问题: 每次我尝试在图形编辑器中移动一个按钮时,所有其他按钮都会在屏幕上以看似随机的模式移动。为什么会这样?
我设置的宽度为 194dp,高度为 64dp。更改这些值没有任何作用。为什么这不会影响我的 ImageButton 的实际宽度和高度?
当使用图形编辑器通过按住 SHIFT 键并拖动角来调整按钮大小时,这不会更改 XML 中的宽度和高度值,只会增加边距。请参阅下面生成的 XML:
<ImageButton
android1:id="@+id/new_customer_button_selector"
android1:layout_width="194dp"
android1:layout_height="64dp"
android1:layout_alignParentBottom="true"
android1:layout_alignRight="@+id/returning_customer_button_selector"
android1:layout_marginBottom="408dp"
android1:layout_marginRight="86dp"
android1:layout_marginTop="89dp"
android1:background="@drawable/new_customer_button_selector"
android1:contentDescription="@string/back_button_desc" />
这是我的最终目标:
请告诉我如何到达那里。这个简单的事情应该更容易。
最佳答案
阅读 developer.android.com/guide/practices/screens_support.html 上提供的信息后,我现在了解了 4 种不同类型的屏幕密度。感谢 CaseyB 提供的链接。
在使用我在 http://members.ping.de/~sven/dpi.html 找到的实用程序后,我计算出我的屏幕密度大约为 160 .
我的问题是 AVD 管理器创建的默认 AVD 将 LCD 密度设置为 240(高)。
将其设置为 160 后,我的项目使用正确大小的按钮呈现。
我将所有可绘制对象都放在可绘制对象文件夹中,因为我正在开发 1 屏幕分辨率和密度。如果我决定使用另一台平板电脑,那么我可能会使用其他文件夹。
提示:不要依赖 Eclipse 图形编辑器来调整 Assets 或调整大小。我不确定它是否完全准确。在尝试调整大小和间距时,我使用旧的编辑 XML 并运行项目的方法。
关于android - ImageButtons 大小和位置在 Eclipse 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12861968/