把一个按钮放在ImageView上
我是Android新手。把一个按钮放在ImageView上
我想知道是否有可能将一个按钮或其他组件放在ImageView上。我已经尝试将图像设置为LinearLayout的背景图像,但是当我在横向和纵向模式之间切换时,图像porportions会更改。
非常感谢。
不要将图像作为背景,您无法控制图像的缩放比例。相反,创建一个RelativeLayout,并将一个ImageView作为其中一个子对象,并且可以将其他RelativeLayout子对象放在任何东西(按钮等)中。
<RelativeLayout ...>
<ImageView (your image) ...>
<Button (the button you want) ... />
</RelativeLayout>
非常感谢。我希望我可以提高我的Android知识,并帮助其他许多人, – gutiory
似乎资源中的顺序很重要,在Button没有为我工作的情况下放置ImageView,但上面的顺序确实如此。 – EtienneSky
你看过Android Developper的拼图合并布局吗?应该解决你的问题:http://developer.android.com/resources/articles/layout-tricks-merge.html
祝你好运!
链接已经死了 – Rule
试试这个代码...这是帮你....
<?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>
试试这个代码.....
在按钮,让paramater设置你的按钮位置....
android:layout_margin or android:layout_alignParent
而且也给图片的路径....
最简单的方法是使用FrameLayout
。
你可以发布你的代码吗? –