【问题标题】:Does the image in a LinearLayout must be the same size?LinearLayout 中的图像是否必须相同大小?
【发布时间】:2011-11-27 12:03:12
【问题描述】:

我写了一个程序来测试MediaPlayer类,它有三个ImageButtons——“play”、“pause”和“stop”。一开始,我为三个ImageButtons使用了三个不同大小的.png图片,并且程序无法在我的AVD上运行,然后我将它们更改为三个具有相同大小的.png图片,然后它这次可以正常运行。

LinearLayout 中使用的图像是否必须相同大小??

这是布局文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    />
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <ImageButton
            android:id="@+id/play"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/play">
        </ImageButton>
        <ImageButton
            android:id="@+id/pause"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/pause">
        </ImageButton>
        <ImageButton
            android:id="@+id/stop"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/stop">
        </ImageButton>
    </LinearLayout>
</LinearLayout>

【问题讨论】:

  • 您使用 android:src 而不是 android:background 有什么原因吗?
  • 但这不是属性的问题

标签: android android-linearlayout imagebutton


【解决方案1】:

我已经测试了您的代码,它很好,但问题是在您删除图像中的 .png 的图像中它会起作用。很酷,因为 .png 已经在图像中,并且您还可以在图像中添加 .png,以便从图像中删除 .png。

【讨论】:

  • 您的意思是它们已经以 PNG 格式编码,并且不需要将它们明确命名为 .png ???但 goodones.zip 也被命名为 .png
  • 我认为问题不在于图片 goodones.zip 如果您使用窗口转到文件夹选项并检查隐藏药水,以便您可以看到差异。
  • 我没有选择这个选项,所以我的图片都被命名为xxx.png
  • 好的已经解决了问题或者仍然有。你现在是否在模拟器中运行项目......酷
【解决方案2】:

LinearLayout 中使用的图像是否必须相同大小??

没有。 wrap_content 参数将使封装的 LinearLayout 仅与最大的 ImageButton 一样大。

问题可能在于可绘制对象的名称。确保所有 .png 图像都遵循 android 命名约定(名称只能包含小写字母、数字 0-9 或下划线)。

还要检查图像本身是否损坏。

【讨论】:

  • 是否有任何工具可以检查图像是否可以在android程序中使用???我从 .jpg 图像中得到一个 .png 图像,我所做的只是将 .jpg 的类型后缀修改为 .png
猜你喜欢
  • 2017-09-20
  • 1970-01-01
  • 2019-11-27
  • 2018-01-07
  • 2018-07-30
  • 1970-01-01
  • 2020-02-23
  • 2017-05-30
  • 2022-01-12
相关资源
最近更新 更多