两个选项卡之间的浮动操作按钮

时间:2014-12-17 20:43:02

标签: java android xml android-layout material-design

我有一个工厂,并希望在两个选项卡之间的通道中使用它,尝试将透明背景放在fragment_main.xml中但没有成功。问题是如何在允许这种灰色条纹切割的同时将两个碎片的背景出现,因为FAB。非常感谢那些帮助我的人。

fragment_main.xml

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:fab="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#0000"
    android:orientation="vertical">

    <br.com.test.common.view.SlidingTabLayout
        android:id="@+id/sliding_tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="0px"
        android:layout_weight="1"
        android:background="#0000"/>

        <com.getbase.floatingactionbutton.FloatingActionButton
            android:id="@+id/pink_icon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            fab:fab_icon="@drawable/ic_add"
            fab:fab_colorNormal="@color/material_orange_500"
            fab:fab_colorPressed="@color/material_orange_a200"
            android:layout_alignParentBottom="true"
            android:layout_gravity="bottom|right"
            android:layout_marginBottom="16dp"/>
</LinearLayout>


fragment_profile.xml

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:background="?android:attr/colorBackground"
    android:layout_weight="1"
    android:gravity="center_horizontal">
    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical">

        <ImageView
            android:id="@+id/profileImage"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:src="@drawable/ic_launcher"
            android:padding="10dp"
            android:scaleType="centerInside"/>

        <TextView
            android:id="@+id/profileName"
            android:layout_below="@id/profileImage"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="teste"
            android:textSize="22sp"/>

        <LinearLayout
            android:id="@+id/ll_1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/profileName"
            android:padding="10dp">

            <android.support.v7.widget.CardView
                xmlns:card_view="http://schemas.android.com/apk/res-auto"
                android:id="@+id/card_view"
                android:layout_gravity="center"
                android:layout_width="fill_parent"
                android:layout_height="150dp"
                card_view:cardCornerRadius="4dp">

                <TextView
                    android:id="@+id/info_text"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:text="teste"/>
            </android.support.v7.widget.CardView>
        </LinearLayout>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/ll_1"
            android:padding="10dp">

            <android.support.v7.widget.CardView
                xmlns:card_view="http://schemas.android.com/apk/res-auto"
                android:id="@+id/card_view_2"
                android:layout_gravity="center"
                android:layout_width="fill_parent"
                android:layout_height="150dp"
                card_view:cardCornerRadius="4dp">

                <TextView
                    android:id="@+id/info_text2"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:text="teste"/>
            </android.support.v7.widget.CardView>
        </LinearLayout>
    </RelativeLayout>
</LinearLayout>


fragment_service.xml

    <?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
    android:gravity="center_horizontal">

   <TableLayout
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_marginTop="20dp"
       android:gravity="center_vertical">

       <TableRow>

           <RelativeLayout
               android:layout_width="wrap_content"
               android:layout_height="wrap_content">

               <ImageView
                   android:id="@+id/imgDP"
                   android:layout_width="wrap_content"
                   android:layout_height="wrap_content"
                   android:layout_centerHorizontal="true"
                   android:src="@drawable/logo_dp"/>

               <TextView
                   android:layout_below="@id/imgDP"
                   android:layout_width="wrap_content"
                   android:layout_height="wrap_content"
                   android:text="DP"/>

            </RelativeLayout>


           <RelativeLayout
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:layout_marginLeft="30dp">

               <ImageView
                   android:id="@+id/imgNA1"
                   android:layout_width="wrap_content"
                   android:layout_height="wrap_content"
                   android:layout_centerHorizontal="true"
                   android:src="@drawable/logo_na"/>

               <TextView
                   android:layout_below="@id/imgNA"
                   android:layout_width="wrap_content"
                   android:layout_height="wrap_content"
                   android:text="NA"/>

           </RelativeLayout>
       </TableRow>
    </TableLayout>
</LinearLayout>

enter image description here

2 个答案:

答案 0 :(得分:1)

Eihschnaehkeee是对的 - 您只需要一个允许重叠的布局。这是要尝试的XML(也为您的按钮添加右边距):

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:fab="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#0000">

    <br.com.test.common.view.SlidingTabLayout
        android:id="@+id/sliding_tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" 
        android:layout_alignParentTop="true" />

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/sliding_tabs"
        android:layout_alignParentBottom="true"
        android:background="#0000"/>

    <com.getbase.floatingactionbutton.FloatingActionButton
        android:id="@+id/pink_icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        fab:fab_icon="@drawable/ic_add"
        fab:fab_colorNormal="@color/material_orange_500"
        fab:fab_colorPressed="@color/material_orange_a200"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_marginBottom="16dp"
        android:layout_marginRight="16dp"/>
</RelativeLayout >

答案 1 :(得分:0)

Eihschnaehkeee和布鲁斯。

我试图把相对布局和刷卡funcinou不多,我尝试使用SlidingTabLayout的android代码https://github.com/googlesamples/android-SlidingTabsBasic/

enter image description here