2016-12-28 86 views
1

我想制作一个位于底部的按钮,并显示在所有片段上。这是包含片段的活动的xml布局。片段滚动和底部按钮始终显示:制作一个在所有片段中显示的按钮android

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:id="@+id/activity_store_info" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="com.sendbest.ibooking.ibooking_customer.StoreInfo"> 

<com.ogaclejapan.smarttablayout.SmartTabLayout 
    android:id="@+id/viewpagertab" 
    android:layout_width="match_parent" 
    android:layout_height="48dp" 
    app:stl_indicatorAlwaysInCenter="false" 
    app:stl_indicatorWithoutPadding="false" 
    app:stl_indicatorInFront="false" 
    app:stl_indicatorInterpolation="smart" 
    app:stl_indicatorGravity="bottom" 
    app:stl_indicatorColor="#ff4081" 
    app:stl_indicatorThickness="4dp" 
    app:stl_indicatorWidth="auto" 
    app:stl_indicatorCornerRadius="2dp" 
    app:stl_overlineColor="#4D000000" 
    app:stl_overlineThickness="0dp" 
    app:stl_underlineColor="#4D000000" 
    app:stl_underlineThickness="1dp" 
    app:stl_dividerColor="#4D000000" 
    app:stl_dividerThickness="1dp" 
    app:stl_defaultTabBackground="?attr/selectableItemBackground" 
    app:stl_defaultTabTextAllCaps="true" 
    app:stl_defaultTabTextColor="#4D000000" 
    app:stl_defaultTabTextSize="12sp" 
    app:stl_defaultTabTextHorizontalPadding="16dp" 
    app:stl_defaultTabTextMinWidth="0dp" 
    app:stl_distributeEvenly="false" 
    app:stl_clickable="true" 
    app:stl_titleOffset="24dp" 
    app:stl_drawDecorationAfterTab="false" 
    /> 

<android.support.v4.view.ViewPager 
    android:id="@+id/viewpager" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_below="@id/viewpagertab" 
    /> 

<Button 
    android:layout_width="match_parent" 
    android:layout_height="60dp" 
    android:layout_below="@id/viewpager" 
    android:gravity="bottom" 
    android:text="bottom button" 
    android:background="#e50013" 
    android:id="@+id/btShopping" 
    android:layout_alignParentBottom="true" 
    /> 

</RelativeLayout> 

该标签和viewpager现在工作正常,但无法显示该按钮。什么是正确的方式来应用这个?

回答

0

添加到您的ViewPager(XML):

android:layout_above="@+id/btShopping" 

,并从同一按钮删除此:

android:layout_below="@+id/viewpager" 

与您的代码的问题是,ViewPager是覆盖整个活动和即使Button设置为低于此值,它也会退出活动屏幕。

+1

谢谢你,我没有尝试过放置layout_above,但没有删除layout_below。这解决了它,我会接受你的答案一旦时间到了 – JerryKo

+0

太好了。随时准备帮助:) –

1

只需从您的按钮上移除此线路android:layout_below="@id/viewpager"。它将显示在所有片段中。

0

因为你设置viewpager mathc_parent并在viewpager下面设置按钮,该按钮不在屏幕上。从按钮

1

删除此

android:layout_below="@id/viewpager" 
1

更改父布局,你的情况在RelativeLayoutLinearLayoutandroid:orientation="vertical"

然后在ViewPager变化android:layout_height="match_parent"android:layout_height="0dp",并添加android:layout_weight="1"另一条线。

希望通过这种方式,你会找到解决方案。

相关问题