Android 按钮位于其下方定义的布局下
大家好,我在我的布局“addfab”中有一个fab按钮,它在大多数手机中都能正确显示,但在android 4.4中,kitkat隐藏在一个相对布局下,该布局下定义了xml。它们都被定义在一个对象下面,这里是我的xmlAndroid 按钮位于其下方定义的布局下,android,layout,floating-action-button,Android,Layout,Floating Action Button,大家好,我在我的布局“addfab”中有一个fab按钮,它在大多数手机中都能正确显示,但在android 4.4中,kitkat隐藏在一个相对布局下,该布局下定义了xml。它们都被定义在一个对象下面,这里是我的xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="matc
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:fbutton="http://schemas.android.com/tools"
android:weightSum="1">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/bar1"
>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:minHeight="?attr/actionBarSize"
android:textAlignment="center"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/addfab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@id/bar1"
android:layout_marginRight="20dp"
android:layout_marginTop="130dp"
android:clickable="true"
android:elevation="2dp"
android:src="@drawable/logo_green"
app:fabSize="normal"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/pic"
android:layout_below="@id/bar1"
android:background="@color/colorPrimary">
<com.mikhaellopez.circularimageview.CircularImageView
android:layout_width="150dp"
android:layout_height="150dp"
android:id="@+id/image_gol"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
app:civ_border_color="@color/colorPrimary"
app:civ_border_width="5dp"
app:civ_shadow="false"
app:civ_shadow_radius="5"
app:civ_shadow_color="#9e9e9e"/>
</RelativeLayout>
我该怎么办?为什么机器人的行为不同?使用
协调布局,而不是相对布局
:
<android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.AppBarLayout>
//Toolbar here
</android.support.design.widget.AppBarLayout>
// your fab and relativelayout here
</android.support.design.widget.CoordinatorLayout>
属性。这还允许您在将来拥有更多功能,如隐藏工具栏
等。您还需要在以后更改remove oldRelativeLayout
的属性,以便使用CoordinatorLayout
看一看:希望有帮助,但我使用的是RelativeLayoutCoordinatorLayout@atefeRelativeLayout
似乎不是最好的选择,因为您有一个带有Fab按钮-AppBarLayout
和工具栏的布局。合理的方法是使用CoordinatorLayout
进行设计,因为它允许更多的功能和最佳的行为。在较新的版本中,它可以工作,因为标高设置为02。在旧设备上,没有标高。因此,您必须更新布局并在文件末尾添加晶圆厂。在XML中,RelativeLayout放在FAB之后。所以,android将把RelativeLayout呈现在晶圆厂之上。谢谢大家,它帮了很多忙
app:layout_anchor="@id/viewpager"
app:layout_anchorGravity="bottom|right|end"