使用图层列表的自定义按钮
我正在尝试制作自定义按钮,下面是代码。我想在我的按钮中实现渐变,角,阴影,而且我想将小图标放在按钮的中心,比如锁定按钮
<Button
android:id="@+id/button5"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_alignBaseline="@+id/button4"
android:layout_alignBottom="@+id/button4"
android:layout_marginLeft="15dp"
android:layout_toRightOf="@+id/button1"
android:shadowColor="#000000"
android:shadowRadius="50"
android:background="@drawable/levelselectionbutton"/>
我实现了渐变和角,并且在某种程度上也实现了图像,但我希望它位于中心,如果我使用重力作用下图像会被放大并且看起来也很模糊。我应该怎么做才能在中心实现它而不被像素化这里是我的图层列表的代码
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle" >
<corners android:radius="20dp" />
<gradient
android:startColor="#7F7F7F"
android:type="linear"
android:endColor="#FFFF"
android:angle="270"/>
</shape>
</item>
<item
android:drawable="@drawable/ic_hh_lock"
android:gravity="center"
/>
我将如何实现列表中另一项的阴影?
I am trying to make custom button below is the code. I want to achieve gradient,corners,shadow in my button and also I want to put small Icon in the center of the button say lock button
<Button
android:id="@+id/button5"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_alignBaseline="@+id/button4"
android:layout_alignBottom="@+id/button4"
android:layout_marginLeft="15dp"
android:layout_toRightOf="@+id/button1"
android:shadowColor="#000000"
android:shadowRadius="50"
android:background="@drawable/levelselectionbutton"/>
I achieved gradient and corners and also image at some extend but I want it in center and if i use gravity then image is getting zoomed nd also looking blur. what should i do to achieve it in the center whitout getting pixalized here is the code of my layerlist
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle" >
<corners android:radius="20dp" />
<gradient
android:startColor="#7F7F7F"
android:type="linear"
android:endColor="#FFFF"
android:angle="270"/>
</shape>
</item>
<item
android:drawable="@drawable/ic_hh_lock"
android:gravity="center"
/>
How will I achieve the shadow one more item in the list?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试将图像包装在位图 xml 中,如下所示:
Try to wrap your image in a bitmap xml like this: