我希望将按钮放在图片视图上方。
请问如何实现?
(请不要建议设置背景,因为我需要ImageView)
请问如何实现?
(请不要建议设置背景,因为我需要ImageView)
设置为背景!
只是开玩笑...你需要的是将视图放在一个RelativeLayout
中。像下面这样做:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:text="blah blah"/>
</RelativeLayout>
注意使用像layout_alignParentLeft
这样的参数来将视图定位在所需的位置。
对我来说,使用RelativeLayout
内部的ImageView
和Button
都有效:
<Button android:layout_centerInParent="true">
...
我同意 @Cristian 的答案。但是,如果你需要按钮的动作监听器,你可以在不使用按钮的情况下添加 onClick 方法到你的 imageView。
还有 ImageButton。我希望这个答案能够为解决你的问题提供一些思路。