我在xml
中定义了一个方形ImageButton
,它的源图像可能以编程方式更改。 无论我想要的内容是什么在右下角(目标是建议用户点击图像并从列表中选择另一个图标)显示一个灰色的小三角形。下面是我对棉花糖发现了一个例子:如何在ImageButton上放置一个三角形的灰色角落?
怎么办呢?
我在xml
中定义了一个方形ImageButton
,它的源图像可能以编程方式更改。 无论我想要的内容是什么在右下角(目标是建议用户点击图像并从列表中选择另一个图标)显示一个灰色的小三角形。下面是我对棉花糖发现了一个例子:如何在ImageButton上放置一个三角形的灰色角落?
怎么办呢?
你可以做这样的事情
<RelativeLayout
android:id="@+id/image_holder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
android:visibility="visible">
<ImageView
android:id="@+id/chosenThing"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:contentDescription="@string/chosen_image"
android:scaleType="centerInside"/>
<ImageView
android:id="@+id/corner"
style="@style/Base.Widget.AppCompat.Button.Borderless"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/chosenThing"
android:layout_alignLeft="@id/chosenThing"
android:layout_alignRight="@id/chosenThing"
android:layout_centerHorizontal="true"
android:clickable="true"
android:padding="8dp"
android:src="@drawable/ic_corner"
android:tint="@color/white"
android:gravity="bottom|right" />
</RelativeLayout>
你可以使用一个微调您的自定义布局,而不是一个的ImageButton,https://developer.android.com/guide/topics/ui/controls/spinner。 html?hl = es-419 – AndroidRuntimeException
@AgustinSivoplás感谢您的回答。如果我没有错误使用'Spinner',我将被迫使用下拉菜单!所以我宁愿使用'ImageButton',因为我可以根据自己的需要定义它的行为。 – Robb1
使用'LayerDrawable' – pskink