相对于屏幕尺寸拉伸图像

时间:2012-02-16 14:54:39

标签: android layout drawable

我的布局有六个按钮。所有这些都是72x72dip的大小,所以它们在小屏幕上看起来更大,反之亦然。

我该如何解决这个问题?我希望按钮的大小相对相同(例如屏幕宽度的10%),但我不知道该怎么做。

这就是我的布局:

enter image description here

可以找到布局的源代码here

3 个答案:

答案 0 :(得分:0)

1 - 您是否已将所有'图像视图'修复为layout_width&高度为72dip? 2 - 通常72dip在每个屏幕尺寸上是相同的...但你仍然可以拥有3个(或者如果你支持XHDPI则为4个)图像的分辨率......

2 - 为你添加4个不同的想法Drawable:

2.1 drawable

2.2 drawable-ldpi

2.3 drawable-mdpi

2.4 drawable-hdpi

为您的图片考虑以下比率: ldpi是3 mdpi是4 hdpi是6

因此,请确保首先制作HDPI图像,这样您就可以使用比率1.5和2来调整其他图像的大小(例如,对于LDPI,只需将2除以)。

3.顺便问一下,你为什么要自己做这一切?好像你在android 4.0上,你为什么不使用Android的新“DashBoard”类呢?

答案 1 :(得分:0)

我通常通过将宽度和高度设置为wrap_content然后调整ImageButton小部件上的layout_weight来执行此操作,以便每个按钮占用相同的空间量。我通常会scaleType="center_inside"使它们很好地排列。然后根据需要使用边距填充TableView的边缘。

答案 2 :(得分:0)

很少有快速观察:

一个。您不需要TableLayout,只需使用LinearLayout

湾您不需要单独的ImageView和TextView,您可以使用

将Button和图像用于它
android:drawableTop="@drawable/"

℃。切勿在任何视图的宽度/高度中使用绝对值,因此请使用wrap_content。

示例布局应如下所示:

<LinearLayout
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:orientation="vertical">

 <!-- Row 1 -->
 <LinearLayout
    android:layout_height="0dp"
    android:layout_width="fill_parent"
    android:layout_weight="1.0"
    android:orientation="horizontal">

 <Button
    android:layout_height="wrap_content"
    android:layout_width="0"
    android:layout_weight="1.0"
    android:text="Preferences"
    android:drawableTop="@drawable/Preferences" />

 <Button
    android:layout_height="wrap_content"
    android:layout_width="0"
    android:layout_weight="1.0"
    android:text="Preferences"
    android:drawableTop="@drawable/Preferences" />

 </LinearLayout>

  .
  .
  .   
</LinearLayout>


</LinearLayout>
相关问题