問題描述
我想為我在我的應用程序中構建的選項卡實現圓角.到目前為止,我能夠想出這個
I want to achieve rounded corners for the tab that I've constructed in my application. So far I was able to come up with this
我希望我的圓角看起來像這樣.(我的編碼方式是只出現左右角,但是當狀態改變時,它看起來像上圖)
I would like my rounded corners to look as so. (I've coded it in such a way that only the right and left corners appear but when the states change it looks like the above image)
以下是我目前編寫的代碼.如何通過代碼實現正確的圓角?
Below is the code that I've written so far. How can I achieve proper rounded corners through code ?
選定的 TAB.XML
SELECTED TAB.XML
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
>
<corners
android:topRightRadius="10dp"
android:bottomLeftRadius="10dp"/>
<gradient
android:startColor="#000"
android:endColor="#000"
android:gradientRadius="400"
android:angle="-270"/>
</shape>
未選擇的 TAB.XML
UNSELECTED TAB.XML
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
>
<gradient
android:angle="90"
android:startColor="#880f0f10"
android:centerColor="#8858585a"
android:endColor="#88a9a9a9"/>
<corners
android:topLeftRadius="10dp"
android:bottomRightRadius="10dp"/>
</shape>
感謝您的回復!:)
推薦答案
我認為你應該使用 4 個形狀:
I think you should use 4 shapes:
左鍵未選中
for left button not selected
選擇左鍵
右鍵未選擇
選擇右鍵
然后編寫選擇器用于 button
背景,請參見左側按鈕的示例(右側類似):
And then write selector to use for button
background, see example for the left button (for the right just the similar):
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true">
<shape android:shape="rectangle">
<corners
android:topLeftRadius="10dp"
android:bottomLeftRadius="10dp"/>
<gradient
android:startColor="#000"
android:endColor="#000"
android:gradientRadius="400"
android:angle="-270"/>
</shape>
</item>
<item>
<shape android:shape="rectangle">
<gradient
android:angle="90"
android:startColor="#880f0f10"
android:centerColor="#8858585a"
android:endColor="#88a9a9a9"/>
<corners
android:topLeftRadius="10dp"
android:bottomLeftRadius="10dp"/>
</shape>
</item></selector>
這篇關于android中TABS的圓角的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!