Pre-Lollipop 上错误的 FAB 位置
Wrong FAB position on Pre-Lollipop
我在 EditText 旁边使用 FAB...
在 Lollipop 上,它工作正常,即恰好在 EditText 旁边,但在 Pre-Lollipop 上,它显示非常附着并且有点偏低......
这是屏幕截图 -
https://i.stack.imgur.com/1QVtF.jpg
这是我在片段布局中使用的代码 -
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:wheel="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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"/>
<android.support.design.widget.TextInputLayout
android:id="@+id/til_id"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_marginTop="8.0dip"
android:layout_marginLeft="10.0dip"
android:layout_marginRight="95.0dip">
<AutoCompleteTextView
android:textColorHint="#ffb7b7b7"
android:id="@+id/editText1"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:hint="Enter Username"
android:ems="10"
android:singleLine="true"
android:inputType="textNoSuggestions">
<requestFocus/>
</AutoCompleteTextView>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/hit"
app:backgroundTint="?attr/colorAccent"
app:rippleColor="#64B5F6"
android:layout_marginLeft="250dp"/>
</RelativeLayout>
这是工作 XML 文件..试试这个 XML ..
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:wheel="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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/hit"
app:backgroundTint="?attr/colorAccent"
app:rippleColor="#64B5F6"
android:layout_alignTop="@+id/til_id"
android:layout_toRightOf="@+id/til_id"
android:layout_toEndOf="@+id/til_id" />
<android.support.design.widget.TextInputLayout
android:id="@+id/til_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<AutoCompleteTextView
android:textColorHint="#ffb7b7b7"
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Username"
android:ems="10"
android:text="trial"
android:singleLine="true"
android:inputType="textNoSuggestions">
<requestFocus/>
</AutoCompleteTextView>
</android.support.design.widget.TextInputLayout>
希望这会很好..
问题是,您为 TextInputLayout
和 AutoCompleteTextView
使用了固定宽度 250dp
。还使用 FloatingActionButton
固定 left-margin
为 250dp
.
这是在所有 Android
版本中显示 same layout
的工作 XML
代码。
更新您的 XML 如下:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:wheel="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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/hit"
app:backgroundTint="?attr/colorAccent"
app:rippleColor="#64B5F6"
android:layout_alignParentRight="true"
android:layout_marginTop="8dp"/>
<android.support.design.widget.TextInputLayout
android:id="@+id/til_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@id/button1"
android:layout_marginTop="8dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="16dp">
<AutoCompleteTextView
android:textColorHint="#ffb7b7b7"
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Username"
android:ems="10"
android:lines="1"
android:inputType="textNoSuggestions">
<requestFocus/>
</AutoCompleteTextView>
</android.support.design.widget.TextInputLayout>
</RelativeLayout>
输出:
希望对你有所帮助~
我在 EditText 旁边使用 FAB... 在 Lollipop 上,它工作正常,即恰好在 EditText 旁边,但在 Pre-Lollipop 上,它显示非常附着并且有点偏低......
这是屏幕截图 - https://i.stack.imgur.com/1QVtF.jpg
这是我在片段布局中使用的代码 -
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:wheel="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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"/>
<android.support.design.widget.TextInputLayout
android:id="@+id/til_id"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_marginTop="8.0dip"
android:layout_marginLeft="10.0dip"
android:layout_marginRight="95.0dip">
<AutoCompleteTextView
android:textColorHint="#ffb7b7b7"
android:id="@+id/editText1"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:hint="Enter Username"
android:ems="10"
android:singleLine="true"
android:inputType="textNoSuggestions">
<requestFocus/>
</AutoCompleteTextView>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/hit"
app:backgroundTint="?attr/colorAccent"
app:rippleColor="#64B5F6"
android:layout_marginLeft="250dp"/>
</RelativeLayout>
这是工作 XML 文件..试试这个 XML ..
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:wheel="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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/hit"
app:backgroundTint="?attr/colorAccent"
app:rippleColor="#64B5F6"
android:layout_alignTop="@+id/til_id"
android:layout_toRightOf="@+id/til_id"
android:layout_toEndOf="@+id/til_id" />
<android.support.design.widget.TextInputLayout
android:id="@+id/til_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<AutoCompleteTextView
android:textColorHint="#ffb7b7b7"
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Username"
android:ems="10"
android:text="trial"
android:singleLine="true"
android:inputType="textNoSuggestions">
<requestFocus/>
</AutoCompleteTextView>
</android.support.design.widget.TextInputLayout>
希望这会很好..
问题是,您为 TextInputLayout
和 AutoCompleteTextView
使用了固定宽度 250dp
。还使用 FloatingActionButton
固定 left-margin
为 250dp
.
这是在所有 Android
版本中显示 same layout
的工作 XML
代码。
更新您的 XML 如下:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:wheel="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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/hit"
app:backgroundTint="?attr/colorAccent"
app:rippleColor="#64B5F6"
android:layout_alignParentRight="true"
android:layout_marginTop="8dp"/>
<android.support.design.widget.TextInputLayout
android:id="@+id/til_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@id/button1"
android:layout_marginTop="8dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="16dp">
<AutoCompleteTextView
android:textColorHint="#ffb7b7b7"
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Username"
android:ems="10"
android:lines="1"
android:inputType="textNoSuggestions">
<requestFocus/>
</AutoCompleteTextView>
</android.support.design.widget.TextInputLayout>
</RelativeLayout>
输出:
希望对你有所帮助~