【问题标题】:Set opacity to sliding tab layout?将不透明度设置为滑动标签布局?
【发布时间】:2015-06-25 23:59:19
【问题描述】:

我在我的 android 应用程序中使用视图寻呼机、fragmentpageradapter 和滑动选项卡布局。我希望为我的滑动选项卡布局设置不透明度,以便您可以在背景中看到部分可滚动内容——我想要把它也弄模糊了,虽然我是一步一步来的。现在,当我为我的 xml 分配不透明度时,在我的背景颜色中,它为我的图标而不是图标后面的背景分配了不透明度。我该如何解决这个问题??

这是我的 xml:

<wxyc.wxyc_consolidate.TabLayoutTools.SlidingTabLayout
    android:id="@+id/sliding_tabs"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:layout_below="@id/wxyc"
    android:layout_gravity="center"
    android:background="#ffcbcbcb"
    android:gravity="center"
    android:layout_alignParentBottom="true"
    />

这里是我实现slidingTabs的地方:

    MyFragmentPagerAdapter fragmentPagerAdapter = new MyFragmentPagerAdapter(getSupportFragmentManager(),
            MainActivity.this, liveStreamFragment);

    // getSupportFragmentManager allows use to interact with the fragments
    // MyFragmentPagerAdapter will return a fragment based on an index that is passed
    viewPager.setAdapter(fragmentPagerAdapter);

    // Initialize the Sliding Tab Layout
    SlidingTabLayout slidingTabLayout = (SlidingTabLayout) findViewById(R.id.sliding_tabs);
    slidingTabLayout.setCustomTabView(R.layout.custom_tab, 0);
    slidingTabLayout.setDistributeEvenly(true);
    slidingTabLayout.setBackgroundColor(Color.rgb(202, 202, 212));


    slidingTabLayout.setFillViewport(true);
    slidingTabLayout.setViewPager(viewPager);

    slidingTabLayout.setViewPager(viewPager);

【问题讨论】:

    标签: android view tabs pager sliding


    【解决方案1】:

    背景中的前 2 个十六进制数字是不透明度。如果您想要半透明背景,请将它们设置为小于 ff 的值。

    如果你想在后台看到SlidingTabLayout,你还需要让ViewPager重叠。

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <android.support.v4.view.ViewPager
            android:id="@+id/viewpager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/white"/>
        <com.example.android.common.view.SlidingTabLayout
            android:id="@+id/sliding_tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:background="#aacbcbcb"/>
    </RelativeLayout>
    

    【讨论】:

    • 我的视图寻呼机现在完全消失了.. @Karaokyo
    • 我有一个匹配父级的高度和一个 FrameLayout 类型的父视图组。你的也一样吗?
    • 我成功了!我只需要在我的 java 代码中删除我的颜色分配。虽然现在我的标签栏位于顶部,但我无法将其固定在底部。这是为什么?
    • 将父布局改为RelativeLayout
    猜你喜欢
    • 2020-07-03
    • 1970-01-01
    • 2011-02-21
    • 1970-01-01
    • 2011-08-05
    • 1970-01-01
    • 2017-04-04
    • 1970-01-01
    • 2011-04-16
    相关资源
    最近更新 更多