如何在android studio中实现段控制?

Sat*_*mar 4 android uisegmentedcontrol segment

在此输入图像描述

我需要在Android中使用分段控件.是否有相同的默认控件?什么是最好和最有效的方法呢?

Suh*_* SH 11

这将有效:

<TableLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="@dimen/padding_extreme"
        android:stretchColumns="*">

    <TableRow
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/padding_very_less"
        android:background="@color/colorBlack"
        android:padding="@dimen/padding_very_less">

        <TextView
            android:id="@+id/seg_one"
            style="@style/barGrapButtons"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="0dp"
            android:background="@color/colorBlack"
            android:text="SegmentOne"
            android:textColor="@color/colorWhite" />

        <TextView
            android:id="@+id/seg_two"
            style="@style/barGrapButtons"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="SegmentTwo" />

        <TextView
            android:id="@+id/seg_three"
            style="@style/barGrapButtons"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="SegmentThree" />
    </TableRow>
</TableLayout>
Run Code Online (Sandbox Code Playgroud)

RES /值/ styles.xml

<style name="barGrapButtons">
    <item name="android:textColor">@color/colorBlack</item>
    <item name="android:textSize">@dimen/small_text</item>
    <item name="android:gravity">center|center_horizontal</item>
    <item name="android:clickable">true</item>
    <item name="android:padding">@dimen/padding_five_dp</item>
    <item name="android:background">@color/colorWhite</item>
    <item name="android:layout_marginLeft">1dp</item>
</style>
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述


Anu*_*Anu 3

我猜您正在谈论顶部带有选项卡的片段。如果您搜索选项卡式活动,将会有很多答案。然而,一个简单的开始方法是

在包中右键->新建->活动->选项卡式活动

将自动创建带有选项卡和片段的活动,其工作方式与图像中显示的流程相同。