我做誰在下面的圖片中需要3個按鈕的TabLayout下對齊,喜歡的應用:
我不知道做什麼是最好的方法,因爲每個人都有不同的邊界。
任何人都可以幫到我嗎? 謝謝!
我終於做到了:
buttons.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:layout_marginLeft="18sp"
android:layout_marginRight="18sp">
<Button
style="?android:textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="31sp"
android:id="@+id/one"
android:text="ONE"
android:textColor="@color/red"
android:layout_weight="1"
android:background="@drawable/button_shape_one" />
<Button
style="?android:textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="31sp"
android:id="@+id/two"
android:text="TWO"
android:textColor="@color/red"
android:layout_weight="1"
android:background="@drawable/button_shape_two"/>
<Button
style="?android:textAppearanceSmall"
android:layout_width="wrap_content"
android:layout_height="31sp"
android:id="@+id/three"
android:text="THREE"
android:textColor="@color/red"
android:layout_weight="1"
android:background="@drawable/button_shape_three"/>
</LinearLayout>
button_shape_one.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/transparent"/>
<stroke android:width="1dp"
android:color="@color/red"
/>
<corners android:bottomRightRadius="0dp"
android:bottomLeftRadius="5dp"
android:topLeftRadius="5dp"
android:topRightRadius="0dp"/>
</shape>
button_shape_two.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:bottom="0dp"
android:left="-2dp"
android:right="-2dp"
android:top="0dp">
<shape android:shape="rectangle" >
<stroke
android:width="1dp"
android:color="@color/red" />
<solid android:color="@color/transparent" />
<padding android:left="10dp"
android:right="10dp"
android:top="5dp"
android:bottom="5dp" />
</shape>
</item>
</layer-list>
button_shape_three.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/transparent"/>
<stroke android:width="1dp"
android:color="@color/red"
/>
<corners android:bottomRightRadius="5dp"
android:bottomLeftRadius="0dp"
android:topLeftRadius="0dp"
android:topRightRadius="5dp"/>
</shape>
結果:
謝謝大家!
https://github.com/Kaopiz/android-segmented-control –