【问题标题】:Floating Action Button between two tabs两个选项卡之间的浮动操作按钮
【发布时间】:2015-02-16 12:40:19
【问题描述】:

我有一个晶圆厂,想在两个选项卡之间通过时拥有它,试图将透明背景放在 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>

【问题讨论】:

  • 不要使用 LinearLayout,而要为 fragment_main 使用 RelativeLayout,因为 LL 没有 Z 重叠。

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


【解决方案1】:

Eihschnaehkeee 和布鲁斯。

我尝试将其设置为相对布局并不再滑动功能,我尝试使用SlidingTabLayout android代码https://github.com/googlesamples/android-SlidingTabsBasic/

【讨论】:

    【解决方案2】:

    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 >
    

    【讨论】:

      猜你喜欢
      • 2021-05-12
      • 2015-09-18
      • 2016-03-27
      • 1970-01-01
      • 1970-01-01
      • 2015-09-27
      • 2016-01-01
      • 2016-10-16
      • 2017-07-10
      相关资源
      最近更新 更多