【问题标题】:nested button inside an image图像内的嵌套按钮
【发布时间】:2011-10-12 09:31:57
【问题描述】:

我尝试在 android XML 中的图像中放置一个常规按钮。如何做呢?我尝试过这样的事情:

<ImageView ....... 
          <Button .... />
</ImageView>

其中的点代表代码。显然这不是方法,因为平台抛出了异常。

谁能帮忙?

【问题讨论】:

    标签: android xml button


    【解决方案1】:

    使用相对布局在图片上插入按钮。

    你的图片应该在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"

    【讨论】:

      【解决方案2】:

      您可以使用 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吗?

      【讨论】:

        【解决方案3】:

        @Uriel Frankel 您也可以尝试创建自定义 ImageView。这是关于 Creating Custom ImageView 的帖子。

        希望对你有帮助。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2018-07-14
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-03-11
          • 2021-05-29
          • 2012-02-09
          • 2020-07-19
          相关资源
          最近更新 更多