【发布时间】:2011-09-05 09:58:07
【问题描述】:
我是 Android 新手。
我想知道是否可以在 ImageView 上放置一个按钮或其他组件。我尝试将图像设置为 LinearLayout 的背景图像,但是当我在横向和纵向模式之间切换时,图像部分会改变。
非常感谢。
【问题讨论】:
-
你能发布你的代码吗?
我是 Android 新手。
我想知道是否可以在 ImageView 上放置一个按钮或其他组件。我尝试将图像设置为 LinearLayout 的背景图像,但是当我在横向和纵向模式之间切换时,图像部分会改变。
非常感谢。
【问题讨论】:
不要将图像作为背景,您无法控制图像的缩放方式。相反,创建一个 RelativeLayout,并将 ImageView 作为其中一个子项,您可以将任何东西(按钮等)作为其他 RelativeLayout 子项。
<RelativeLayout ...>
<ImageView (your image) ...>
<Button (the button you want) ... />
</RelativeLayout>
【讨论】:
试试这个代码......它可以帮助你......
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/imageviewMain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="Path "
/>
<Button android:id="@+id/but2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
试试这个代码.....
在按钮中给参数设置按钮位置....
android:layout_margin or android:layout_alignParent
并且还给出图像路径....
【讨论】:
最简单的方法是使用FrameLayout。
【讨论】: