【发布时间】:2011-10-12 09:31:57
【问题描述】:
我尝试在 android XML 中的图像中放置一个常规按钮。如何做呢?我尝试过这样的事情:
<ImageView .......
<Button .... />
</ImageView>
其中的点代表代码。显然这不是方法,因为平台抛出了异常。
谁能帮忙?
【问题讨论】:
我尝试在 android XML 中的图像中放置一个常规按钮。如何做呢?我尝试过这样的事情:
<ImageView .......
<Button .... />
</ImageView>
其中的点代表代码。显然这不是方法,因为平台抛出了异常。
谁能帮忙?
【问题讨论】:
使用相对布局在图片上插入按钮。
你的图片应该在RelativeLayout的背景标签中给出。
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="50dp"
android:background="@drawable/list_nav"
>
<Button
android:layout_width="63dp"
android:layout_height="36dp"
android:id="@+id/mapbutton"
android:layout_marginTop="7dp"
android:layout_marginLeft="4dp"
android:layout_alignParentLeft="true"
/>
此示例在图像左侧添加按钮,因为我使用了 layout_alignParentLeft="true"
【讨论】:
您可以使用 FrameLayout:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView android:id="@+id/myImage"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:src="@drawable/icon" />
<Button android:id="@+id/myButton"
android:layout_width="150dip"
android:layout_height="150dip"
android:text="My Button"/>
</FrameLayout>
您没有写出为什么需要图像和按钮。你知道ImageButton吗?
【讨论】:
@Uriel Frankel 您也可以尝试创建自定义 ImageView。这是关于 Creating Custom ImageView 的帖子。
希望对你有帮助。
【讨论】: