2017-01-02 53 views
0

我在xml中定义了一个方形ImageButton,它的源图像可能以编程方式更改。 无论我想要的内容是什么在右下角(目标是建议用户点击图像并从列表中选择另一个图标)显示一个灰色的小三角形。下面是我对棉花糖发现了一个例子:如何在ImageButton上放置一个三角形的灰色角落?

enter image description here

怎么办呢?

+3

你可以使用一个微调您的自定义布局,而不是一个的ImageButton,https://developer.android.com/guide/topics/ui/controls/spinner。 html?hl = es-419 – AndroidRuntimeException

+0

@AgustinSivoplás感谢您的回答。如果我没有错误使用'Spinner',我将被迫使用下拉菜单!所以我宁愿使用'ImageButton',因为我可以根据自己的需要定义它的行为。 – Robb1

+0

使用'LayerDrawable' – pskink

回答

0

你可以做这样的事情

  <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> 
+0

感谢您的答案!你在哪里得到了@ drawable/ic_corner?如果目标是重叠两个“ImageViews”,我不应该使用“FrameLayout”而不是“RelativeLayout”? – Robb1

+0

@ Robb1不,您需要使用'RelativeLayout',因为'layout_align..'属性会允许第二张图片相对于第一张图片拉伸。 '@ drawable/ic_corner' - 只是你的角落里的一些图像。用油漆画出来,或者做成XML(如果可能的话)。 – Ekalips