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中选择器,不过写的代码是同上的,这里不再介绍;只需要在监听的时候改变其他两个的状态即可!
點(diǎn)擊查看更多內(nèi)容
為 TA 點(diǎn)贊
評(píng)論
評(píng)論
共同學(xué)習(xí),寫(xiě)下你的評(píng)論
評(píng)論加載中...
作者其他優(yōu)質(zhì)文章
正在加載中
感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說(shuō)多少就多少
贊賞金額會(huì)直接到老師賬戶(hù)
支付方式
打開(kāi)微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊(cè)有機(jī)會(huì)得
100積分直接送
付費(fèi)專(zhuān)欄免費(fèi)學(xué)
大額優(yōu)惠券免費(fèi)領(lǐng)