当前位置:首页 > 安卓源码 > 技术博客 >

Button实现一遍直角一边半圆和Button之间无距离

时间:2016-12-13 13:07 来源:互联网 作者:源码搜藏 浏览: 收藏 挑错 推荐 打印

1.Button之间无距离:当我们在xml中写两个Button的时候他们的实际距离是8dp;想让我们的Button之间无距离的话只要把距离设置为-8dp即可:android:layout_marginLeft=-8dp 2.Button实现左边半圆右边直角或者右边半圆左边直角: 实现左边半圆右边直角的:国控 ?

Button实现一遍直角一边半圆和Button之间无距离

1.Button之间无距离:当我们在xml中写两个Button的时候他们的实际距离是8dp;想让我们的Button之间无距离的话只要把距离设置为-8dp即可:android:layout_marginLeft="-8dp"

2.Button实现左边半圆右边直角或者右边半圆左边直角:

实现左边半圆右边直角的:国控

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- 填充的颜色:这里设置为红色 -->
    <solid android:color="#FF0000"/>
    <!-- 设置按钮的四个角为弧形   android:radius 弧形的半径 -->
    <corners android:bottomLeftRadius="10dp"
            android:topLeftRadius="10dp"
            android:bottomRightRadius="0dp"
            android:topRightRadius="0dp"/>
</shape>

实现中间的无直角:省控

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- 填充的颜色:这里设置为红色 -->
    <solid android:color="#FF0000"/>
</shape>

实现右边的左边直角右边圆角:小型站

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- 填充的颜色:这里设置为红色 -->
    <solid android:color="#FF0000"/>
    <!-- 设置按钮的四个角为弧形   android:radius 弧形的半径 -->
    <corners android:bottomLeftRadius="0dp"
             android:topLeftRadius="0dp"
             android:topRightRadius="10dp"
             android:bottomRightRadius="10dp"/>
</shape>

选择器里面的状态在代码中已经介绍,在这里不再介绍,把xml中的整体效果展示一下:

 

<LinearLayout
    android:id="@+id/ll_top"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:layout_margin="10dp"
    android:orientation="horizontal">

    <Button
        android:id="@+id/tv_country"
        android:layout_width="90dp"
        android:layout_height="wrap_content"
        android:text="国控"
        android:background="@drawable/horn_fragment_site"
        android:textSize="25sp"/>

    <Button
        android:id="@+id/tv_province"
        android:layout_width="90dp"
        android:layout_height="wrap_content"
        android:text="省控"
        android:background="@drawable/horn_fragment_site_mid"
        android:layout_marginLeft="-8dp"
        android:textSize="25sp"/>

    <Button
        android:layout_width="90dp"
        android:layout_height="wrap_content"
        android:text="小型站"
        android:layout_marginLeft="-8dp"
        android:background="@drawable/horn_fragment_right"
        android:textSize="25sp"/>

</LinearLayout>

如果你想在代码中实现点击换颜色的话,你需要再写3中选择器,不过写的代码是同上的,这里不再介绍;只需要在监听的时候改变其他两个的状态即可!

Button实现一遍直角一边半圆和Button之间无距离 转载https://www.codesocang.com/appboke/33982.html

技术博客阅读排行

最新文章