我正在尝试将fab按钮添加到我的布局中,以便将其用作搜索按钮。我想将其放置在版式的右下角,一小部分将不在版式中。
在我的预览屏幕上看起来不错(如我所愿): My preview screen
但是,运行应用程序时,晶圆厂的位置不同: the running app screen
这是我的布局xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimaryDark"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:src="@drawable/departure" />
<AutoCompleteTextView
android:id="@+id/actvDepartureAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:hint="Departure From"
android:imeOptions="actionDone"
android:textColor="#e8e9ff"
android:textColorHint="#e8e9ff" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:src="@drawable/landing" />
<AutoCompleteTextView
android:id="@+id/acTvLandingAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:hint="Landing At"
android:textColor="#e8e9ff"
android:textColorHint="#e8e9ff" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:src="@drawable/calendar" />
<EditText
android:id="@+id/etDepartureDateAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:hint="Departure Date"
android:textAlignment="center"
android:textColor="#e8e9ff"
android:textColorHint="#e8e9ff" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:id="@+id/imgBackDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:src="@drawable/calendar" />
<EditText
android:id="@+id/etBackDateAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Back Date"
android:textAlignment="center"
android:textColor="#e8e9ff"
android:textColorHint="#e8e9ff" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:gravity="center"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:src="@drawable/person" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left"
android:text="Passengers"
android:textColor="#e8e9ff" />
<EditText
android:id="@+id/etNumOfPassengers"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:text="2"
android:textColor="#e8e9ff" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:gravity="center"
android:text="Round Trip"
android:textColor="#e8e9ff" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/chkIsDirect"
android:visibility="invisible"
android:text="Direct Only" />
</LinearLayout>
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/btnSearchFlight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:clickable="true"
android:src="@drawable/search_flight"
app:useCompatPadding="true"
app:layout_anchor="@id/chkIsDirect"
app:layout_anchorGravity="bottom|right|end"/>
</android.support.design.widget.CoordinatorLayout>
答案 0 :(得分:0)
在FAB标签中
尝试将layout_marginRight
更改为{{1}}
答案 1 :(得分:0)
尝试在FAB的以下行中添加此内容-
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
答案 2 :(得分:0)
尝试这种布局
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<android.support.design.widget.CoordinatorLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
>
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<include
android:id="@+id/main_page_toolbar"
layout="@layout/app_tool_bar">
</include>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/main_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
>
<android.support.design.widget.FloatingActionButton
android:id="@+id/add_post_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_marginBottom="10dp"
android:layout_marginRight="10dp"
android:src="@mipmap/floating_add_btn"
app:fabSize="normal" />
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>