【问题标题】:How to Implement Segment Control in android studio?如何在 android studio 中实现段控制?
【发布时间】:2017-09-23 17:16:51
【问题描述】:

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

【问题讨论】:

标签: android uisegmentedcontrol segment


【解决方案1】:

这将起作用:

<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>

res/values/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>

【讨论】:

    【解决方案2】:

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

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

    将自动创建一个带有选项卡和片段的活动,该活动与您在图像中显示的流程一样工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多