Add button on Sliding Tab Layout

╄→гoц情女王★ 提交于 2019-12-23 05:05:28

问题


I want to add a custom button on my Tab Layout. This expand button will expand my current tab view. I already have implemented all the functionalities given in google's sliding tab.


回答1:


You can make it with the help of FrameLayout.

<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="280dp"
android:layout_gravity="center"
app:cardElevation="8dp"
card_view:cardCornerRadius="5dp">

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

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


        <SlidingTabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#2D73A9"
            android:elevation="2dp" />

        <android.support.v4.view.ViewPager
            android:id="@+id/pager"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1" />

    </LinearLayout>

    <FrameLayout
        android:id="@+id/buttonPanel"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_gravity="top|end"
        android:layout_marginEnd="0dp"
        android:layout_marginRight="0dp">

        <Button
            android:id="@+id/expand"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/img_chart_expand"
            android:visibility="gone" />
    </FrameLayout>

</FrameLayout>



回答2:


Does it make sense to add the button next to the TabLayout? It's much easier to manage that (just a button with alignParentRight and the tabLayout to_leftOf), and the result will be the same.



来源:https://stackoverflow.com/questions/33125767/add-button-on-sliding-tab-layout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!