【问题标题】:Adding fab Button at the junction of two ViewPager widgets在两个 ViewPager 小部件的交界处添加 fab Button
【发布时间】:2015-07-08 06:50:23
【问题描述】:

我已经实现了一个导航抽屉。在导航抽屉的 FrameLayout 中,我添加了一个片段,其中包含 2 个 ViewPager,每个 ViewPager 正好占屏幕的一半。现在我想在这两个查看器的交界处添加一个 FAB 按钮,如下所示。

在我的例子中,两个浏览器都占据了半屏,这与图像中显示的略有不同。有人可以帮我在路口拿到 FAB。

包含 2 个浏览器的片段代码如下:

<?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.support.v4.view.ViewPager
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/shirt_section"
        android:layout_weight="1"
        android:layout_width="match_parent"
        android:layout_height="0dp" />

    <android.support.v4.view.ViewPager
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/pant_section"
        android:layout_weight="1"
        android:layout_width="match_parent"
        android:layout_height="0dp" />
</LinearLayout>  

【问题讨论】:

    标签: android android-fragments android-viewpager floating-action-button


    【解决方案1】:

    你可以将你的线性布局封装到 FrameLayout 中,然后像这样添加你的按钮:

    <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="match_parent">
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">
    
              ...
        </LinearLayout>  
        <ImageButton
            android:layout_gravity="center_vertical|right"
            ...
        />
    </FrameLayout>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-20
      • 2012-08-05
      • 2013-10-21
      • 1970-01-01
      • 1970-01-01
      • 2018-12-20
      相关资源
      最近更新 更多