android - float 操作按钮未正确显示

标签 android xamarin.android android-tablayout floating-action-button

我在 TabLayout 内的 Fragment 中有一个 float 操作按钮

当页面加载时,按钮保持这样:

enter image description here

在我点击“Quilometragem final”字段后,键盘出现,然后我的按钮保持在正确的位置:

enter image description here

如何解决此问题以在页面加载时在正确位置显示我的 float 操作按钮

这是我的布局的 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 的评论,我能够修复此bug 阅读this .

解决方案是在我的 Fragment 中的 OnCreateView 中添加以下代码:

_linearLayout.Post(new Runnable(() =>
{
    _linearLayout.RequestLayout();
}));

为什么会这样?

如告知here ,

Posting requestLayout() works because the dependency graph is being built in the onMeasure() method of CoordinatorLayout. After building the graph once, the findAnchorView() method was called for every child. In the next pass when building the graph in onMeasure() the method dependsOn() returns correct result (unless some new views were added, for them it will not work) and the graph builds correctly. It has to be called in post(), because calling requestLayout() before the previous measure/layout pass begins does not cause new pass.

关于android - float 操作按钮未正确显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50252793/

相关文章:

android - Viewpager 和 Tab 的滚动问题

opengl - Xamarin Android 播放器 : OpenGL server is unreachable

c# - 如何使用 PushSharp 获取 GCM 错误消息 'NotRegistered'

android - 标签栏布局 Activity 标签文本颜色与原色相同

javascript - 应用程序以垂直模式打开,而不是水平模式

android - 在 MonoDroid 中以编程方式隐藏键盘

android - 更改 viewPager 滑动方向

java - 如何从以下cataLog中找到异常?

适用于 Android 的 Java C++ 包装器 : how to wrap c++ templates

android - 如何配置 Gradle 任务序列