本文介绍了如何使按钮看起来像一个列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的应用程序我有按钮,它们看起来像这样:
In my app I have buttons which look like this:
我想使它们看起来是这样的:
I want to make them look like this :
我的 background.xml
如下:
<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@drawable/solid" />
<item android:drawable="@drawable/shape" />
</layer-list>
solid.xml
如下:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#ababab" />
</shape>
而 shape.xml
如下:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#ffffff" />
<stroke android:width="3dp" color="#ff000000" />
<corners android:radius="15dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
我
如何才能让按键所需的外观?
How can I get the desired appearance of the buttons?
推荐答案
最佳状态:
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:topLeftRadius="5dp"
android:topRightRadius="5dp" />
<padding
android:left="3dp"
android:top="3dp"
android:right="3dp"
android:bottom="3dp" />
<solid
android:color="#ffffffff" />
<stroke
android:width="2dp"
android:color="#ff000000" />
</shape>
中东形状:
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<padding
android:left="3dp"
android:top="3dp"
android:right="3dp"
android:bottom="3dp" />
<solid
android:color="#ffffffff" />
<stroke
android:width="2dp"
android:color="#ff000000" />
</shape>
底部形状:
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:bottomLeftRadius="5dp"
android:bottomRightRadius="5dp" />
<padding
android:left="3dp"
android:top="3dp"
android:right="3dp"
android:bottom="3dp" />
<solid
android:color="#ffffffff" />
<stroke
android:width="2dp"
android:color="#ff000000" />
</shape>
例如:
<Button
android:background="@drawable/top"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:text="Top" />
<Button
android:background="@drawable/middle"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginTop="-2dp"
android:text="Middle" />
<Button
android:background="@drawable/bottom"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginTop="-2dp"
android:text="Bottom" />
看安卓layout_marginTop = - 2DP
- 你需要它与底部按键的边框重叠顶部的按钮边框
Look at android:layout_marginTop="-2dp"
- you need it to overlap border of top button with border of bottom button
结果(图形是不那么好,SRY):
Result (the graphic is not so good, sry):
在一些调整,你就会有一个形状如您所愿。
After some tweaking you'll have a shape as you expect.
我的调整:
My tweaking:
这篇关于如何使按钮看起来像一个列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!