android - 浮动操作按钮未正确显示
问题描述
我有一个floating action button
在我的Fragment
里面TabLayout
。
当页面加载时,按钮保持如下:
单击“Quilometragem final”字段后,键盘出现,然后我的按钮保持在正确的位置:
如何解决此问题以floating action button
在页面加载时显示我的正确位置?
这是我的布局的 xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:focusableInTouchMode="true">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="10dp"
android:layout_marginLeft="@dimen/common_margin"
android:layout_marginRight="@dimen/common_margin">
<!-- another fields -->
<!-- KM FINAL -->
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<TextView
android:text="@string/end_exam_mileage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="25sp"
android:fontFamily="sans-serif-condensed"
android:textColor="@color/primary" />
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/txtFinalKM"
android:fontFamily="sans-serif-condensed"
android:inputType="number"
android:hint="@string/end_exam_insert_mileage"
android:textSize="25sp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
</LinearLayout>
<!-- NEXT BUTTON -->
<com.github.clans.fab.FloatingActionButton
android:id="@+id/fab_next_information"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginRight="@dimen/common_margin"
android:layout_marginBottom="@dimen/common_margin"
android:src="@drawable/icon_fab_mini_next"
android:clickable="true"
app:fab_shadowColor="#00FFFFFF"
app:fab_colorNormal="#272B35"
app:fab_colorPressed="@color/accent"
app:fab_colorRipple="#272B35" />
</android.support.design.widget.CoordinatorLayout>
</LinearLayout>
解决方案
多亏了 Aswin P Ashok 的评论,我才能够通过阅读这篇文章来修复这个错误。
OnCreateView
解决方案是在 my中添加以下代码Fragment
:
_linearLayout.Post(new Runnable(() =>
{
_linearLayout.RequestLayout();
}));
为什么这行得通?
正如这里所说,
发布 requestLayout() 有效,因为依赖关系图是在 CoordinatorLayout 的 onMeasure() 方法中构建的。构建图一次后,为每个孩子调用 findAnchorView() 方法。在下一个过程中,在 onMeasure() 中构建图形时,dependsOn() 方法返回正确的结果(除非添加了一些新视图,否则它将无法正常工作)并且图形构建正确。它必须在 post() 中调用,因为在前一个度量/布局传递开始之前调用 requestLayout() 不会导致新传递。
推荐阅读
- android - WorkManager 实例即使在应用程序被卸载后仍保持活动状态 (?)
- java - 在不使用额外反斜杠的情况下读取路径文件
- php - 拉拉维尔。在foreach循环中将不正确的参数传递给destroy()
- excel - excel conditional formatting validate date
- kettle - 跳过在 Kettle 上读取的 csv 中的第一行
- elasticsearch - 如何查询elasticsearch的大于和小于?
- visual-studio-code - 在 VS.code 中使用现有的文档格式化程序
- java - Apache Camel File IO on linux
- node.js - How can I compare content of two web pages?
- sql-server - Linux SQL Server:如何允许远程连接?