在android中使用最新的TabLayout提升中心选项卡

时间:2016-04-29 08:35:36

标签: android github android-tablayout

我发现较旧的github使用tabhost。 github address

但不推荐使用tabhost。

现在可以使用TabLayout提升中心选项卡吗?

1 个答案:

答案 0 :(得分:0)

您可以尝试使用此代码,它适用于我:

我的XML文件:

set.seed(357)

# simulate some data, rnorm() is used to add some noise
x <- seq(from = 4, to = 6, length.out = 10)
y <- 1986*0.840897^x + rnorm(10, sd = 30)
xy <- data.frame(x, y)

# define function
myfun <- function(x) 1986*0.840897^x

library(ggplot2)

ggplot(xy, aes(x = x, y = y)) +
  theme_bw() +
  geom_point() +
  stat_function(fun = myfun)

我的活动档案:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TabHost
        android:id="@+id/tabHost"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <TabWidget
                android:id="@android:id/tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"></TabWidget>

            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <LinearLayout
                    android:id="@+id/tab1"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="#ffc916"
                    android:orientation="vertical">

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:text="Android" />

                </LinearLayout>

                <LinearLayout
                    android:id="@+id/tab2"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="#da8200"
                    android:orientation="vertical">

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:text="Iphone tab" />
                </LinearLayout>

                <LinearLayout
                    android:id="@+id/tab3"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="#5b89ff"
                    android:orientation="vertical">

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:text="Windows tab" />
                </LinearLayout>
            </FrameLayout>
        </LinearLayout>
    </TabHost>

</LinearLayout>