【问题标题】:How to draw a ellipse for imageButton xamarin.android? [duplicate]如何为 imageButton xamarin.android 绘制一个椭圆? [复制]
【发布时间】:2016-05-04 15:55:36
【问题描述】:

ImageButton 的默认样式是正方形。

<ImageButton
    android:id="@+id/imgNextPlayer"
    android:layout_width="40dp"
    android:layout_height="40dp"
    android:background="@android:color/white"
    android:layout_gravity="top"
    android:tint="#757575" />

【问题讨论】:

  • 天哪,我已经告诉过你了:请使用&lt;!-- language: c# --&gt; 进行格式化,而不是使用代码 sn-p。 那是 C# 而不是 HTML!
  • 调用 C# 有点牵强。是的,xamarin 主要是一个 C# 平台,但这是一个 android xml 资源。

标签: xamarin xamarin.android


【解决方案1】:

您是否尝试在可绘制文件夹mybuttonshape.xml 中创建形状:

像这样:

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

然后将按钮的背景设置为此可绘制对象:

<ImageButton
    android:id="@+id/imgNextPlayer"
    android:layout_width="40dp"
    android:layout_height="40dp"
    android:background="@drawable/mybuttonshape"
    android:layout_gravity="top"
    android:bottomRightRadius="10dp"
    android:bottomLeftRadius="10dp"
    android:topLeftRadius="10dp"
    android:topRightRadius="10dp" />

查看question 了解其他选项

【讨论】:

    【解决方案2】:

    您可以将 android:background="@android:.... 设置为可绘制对象:

    android:background="@drawable/myellipsebutton"
    

    然后添加一个名为myellipsebutton.xml的drawable:

    • 资源/Drawable/myellipsebutton.xml

    在这个drawable resource中,你可以定义按钮的形状,在这个例子中我使用oval而不是rectanglelinering也可用:


    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:state_pressed="true">
            <shape android:shape="oval">
                <gradient android:startColor="#F44336" android:endColor="#E57373" android:angle="270" />
                <stroke android:width="10dp" android:color="#607D8B" />
            </shape>
        </item>
        <item android:state_focused="true">
            <shape android:shape="oval">
                <gradient android:startColor="#3F51B5" android:endColor="#9FA8DA" android:angle="270" />
                <stroke android:width="10dp" android:color="#607D8B" />
            </shape>
        </item>
        <item>
            <shape android:shape="oval">
                <gradient android:startColor="#2196F3" android:endColor="#BBDEFB" android:angle="270" />
                <stroke android:width="1dp" android:color="#607D8B" />
            </shape>
        </item>
    </selector>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-02-05
      • 1970-01-01
      • 1970-01-01
      • 2022-01-09
      • 2013-01-05
      • 1970-01-01
      • 2012-09-04
      相关资源
      最近更新 更多