java - 两个选项卡之间的 float 操作按钮

标签 java android xml android-layout material-design

我有一个 fab,希望在两个选项卡之间通过时拥有它,尝试将透明背景放入fragment_main.xml 但没有成功。问题实际上是如何放置出现的两个 fragment 的背景,同时允许由于 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

最佳答案

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 >

关于java - 两个选项卡之间的 float 操作按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27534512/

相关文章:

javascript - "Uncaught TypeError: Cannot call method ' indexOf ' of undefined"选中jqgrid行时

java - 将静态变量值传递给另一个类

java - Java 9 或更高版本中的预计泛型特化,vs List<int> : how will . remove() 工作?

java - 在午夜运行服务而不启动应用程序

android - 使用用户名和密码从应用程序在 Web 浏览器中打开 URL

android - 通过指纹验证保护数据

java - 使用 DPLL sat 求解器求解

android - 为什么要使用 Retrofit?

xml - 使用嵌套表将数据集写入 xml

java - XSLT:XTSE0010:fo:block 元素不得包含 xsl:param 元素