在Android中为页面中的所有片段添加页脚的最佳方法是什么?

时间:2017-04-28 07:56:23

标签: android android-fragments xamarin.android

我有一个Android应用程序(Xamarin.Android),它有很多片段。 所有片段都有到底部网站的链接。

理想情况下,我想将其创建为带有网站链接的自定义片段,并添加到所有片段中。

但我没有找到任何方法可以将这个片段添加到每个片段的XML中而无需编码。 我不想将自定义片段添加到代码中其他片段的FrameLayout。

如果有人知道这种页脚的最佳解决方案,请告诉我。 感谢。

2 个答案:

答案 0 :(得分:0)

  1. 您可以将页脚添加到活动中,并将片段用于其他屏幕。 (显然主要活动中页脚上方的片段框架布局)

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/footer">
    
    </FrameLayout>
    
    <FrameLayout
        android:id="@+id/footer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="30dp"
            android:layout_gravity="center"
            android:text="Footer content"/>
    </FrameLayout>
    

  2. 您可以使用视图底部的页脚视图进行自定义布局,并为所有父布局扩展它。

答案 1 :(得分:0)

这是我找到的简单方法。

  • 为页脚创建新的XML布局
  • 为此页脚创建自定义片段类
  • 根据需要将此页脚片段添加到布局结尾,如下所示

这就是全部!