图像中的嵌套按钮

Uri*_*kel 2 xml android button

我尝试在Android XML中的图像中放置一个常规按钮.怎么做到呢?我试过这样的事情:

<ImageView ....... 
          <Button .... />
</ImageView>
Run Code Online (Sandbox Code Playgroud)

点代表代码.显然这不是方法,因为平台引发了异常.

有人可以帮忙吗?

Abh*_*bhi 6

使用相对布局在图像上插入按钮.

你的图像应该在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"
          />
Run Code Online (Sandbox Code Playgroud)

这个例子在图像的左侧添加了按钮,因为我使用了layout_alignParentLeft ="true"