【问题标题】:Android layout XML for button with image background具有图像背景的按钮的 Android 布局 XML
【发布时间】:2020-03-21 15:38:59
【问题描述】:

[android 布局活动][1]

** 我想让按钮的边缘变成圆形,并为每个按钮添加不同的图像! 如果我创建一个带角的资源 XML (custom_button) 并将其添加到每个按钮作为背景我不能再添加图像**

【问题讨论】:

    标签: xml android-studio android-layout button


    【解决方案1】:

    您可以尝试像这样添加您的自定义形状

    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
        <item>
            <shape android:shape="rectangle" 
              android:padding="5dp">
                <corners
                     android:bottomRightRadius="4dp"
                     android:bottomLeftRadius="4dp"
                     android:topLeftRadius="4dp"
                     android:topRightRadius="4dp"/>
             </shape>
       </item>
       <item android:drawable="@drawable/yourImage" />
    </layer-list>
    

    【讨论】:

      【解决方案2】:

      如果你愿意

      1. 添加圆角

      2. 添加图片作为背景。

      我建议您使用 ImageButton 而不是 Button。

      1.创建将其命名为 circularedge.xml 的 xml 文件

       <?xml version="1.0" encoding="utf-8"?>
              <shape xmlns:android="http://schemas.android.com/apk/res/android">
                  <solid android:color="#33DDFF" />
                  <corners android:radius="4dp" />
              </shape>
      

      根据自己的喜好更改属性。

      2。在你的 ImageButton 添加这个属性 android:background="@drawable/circularedge"

      <ImageButton
                      android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:id="@+id/imageButton"
                      android:src="@drawable/friends"
                      android:background="@drawable/circularedge" />
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-07-29
        • 2012-05-15
        • 1970-01-01
        相关资源
        最近更新 更多