浮动操作按钮呈现效果不佳
Floating Action Button bad rendering
我在使用应用程序中的浮动操作按钮时遇到了一些问题。在 Android Studio 模拟器中,它看起来不错,在 xml 文件的 "design" 视图中,在应用程序的模拟器中,但在真实设备中,当我 运行该应用程序没有圆形,而是椭圆形。
此外,此错误仅在某些执行时发生......昨天 FAB 在我的设备上也是循环的,但今天不是(我没有修改 xml 部分并且在 Java 方面我没有' t 处理它的方面)...
这是我定义按钮的 .xml 文件:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coor"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="1">
<RelativeLayout
android:id="@+id/relative"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="@dimen/activity_horizontal_margin"
android:layout_weight="0.88">
<!-- Other elements-->
<!-- Parent element-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/etEntrate"
android:textSize="@dimen/subtitles"
android:padding="@dimen/activity_horizontal_margin"
android:layout_alignRight="@+id/data"
android:layout_alignEnd="@+id/data"
android:layout_below="@+id/etSpese"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:layout_marginEnd="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/activity_horizontal_margin"
android:layout_marginBottom="@dimen/activity_horizontal_margin"/>
<!--FAB-->
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
app:srcCompat="@drawable/plus"
android:layout_alignTop="@+id/etEntrate"
android:layout_marginTop="59dp"
android:layout_alignLeft="@+id/etEntrate"
android:layout_alignStart="@+id/etEntrate"
android:layout_alignRight="@+id/etEntrate"
android:layout_alignEnd="@+id/etEntrate" />
<!--other elements-->
</RelativeLayout>
</LinearLayout>
这里有两张图片,展示了我如何在我的设备上看到 FAB 以及它在模拟器上的样子:
我设备上的 FAB:
FAB 关于 Android Studio 的设计视图
有没有人对此有所了解?谢谢!
当然,FAB 宽度和高度设置为 wrap_content
,但您试图同时向左和向右对齐,这就是它拉伸的原因。
只需删除其中一个即可。
当您在水平方向使用重力时,您必须使用 layout_width=0dp & 在垂直方向的情况下,layout_height=0dp 用于布局中的每个子项。
或
只需从相对布局中删除浮动操作按钮,因为您已经在使用坐标布局。
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coor"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/relative"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="@dimen/activity_horizontal_margin"
android:layout_weight="0.88">
<!-- Other elements-->
<!-- Parent element-->
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/etEntrate"
android:textSize="@dimen/subtitles"
android:padding="@dimen/activity_horizontal_margin"
android:layout_alignRight="@+id/data"
android:layout_alignEnd="@+id/data"
android:layout_below="@+id/etSpese"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:layout_marginEnd="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/activity_horizontal_margin"
android:layout_marginBottom="@dimen/activity_horizontal_margin"/>
<!--FAB-->
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:clickable="true"
app:srcCompat="@drawable/plus"
android:layout_alignTop="@+id/etEntrate"
android:layout_marginTop="59dp"
android:layout_alignLeft="@+id/etEntrate"
android:layout_alignStart="@+id/etEntrate"
android:layout_alignRight="@+id/etEntrate"
android:layout_alignEnd="@+id/etEntrate" />
<!--other elements-->
</RelativeLayout>
我在使用应用程序中的浮动操作按钮时遇到了一些问题。在 Android Studio 模拟器中,它看起来不错,在 xml 文件的 "design" 视图中,在应用程序的模拟器中,但在真实设备中,当我 运行该应用程序没有圆形,而是椭圆形。 此外,此错误仅在某些执行时发生......昨天 FAB 在我的设备上也是循环的,但今天不是(我没有修改 xml 部分并且在 Java 方面我没有' t 处理它的方面)...
这是我定义按钮的 .xml 文件:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coor"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="1">
<RelativeLayout
android:id="@+id/relative"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="@dimen/activity_horizontal_margin"
android:layout_weight="0.88">
<!-- Other elements-->
<!-- Parent element-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/etEntrate"
android:textSize="@dimen/subtitles"
android:padding="@dimen/activity_horizontal_margin"
android:layout_alignRight="@+id/data"
android:layout_alignEnd="@+id/data"
android:layout_below="@+id/etSpese"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:layout_marginEnd="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/activity_horizontal_margin"
android:layout_marginBottom="@dimen/activity_horizontal_margin"/>
<!--FAB-->
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
app:srcCompat="@drawable/plus"
android:layout_alignTop="@+id/etEntrate"
android:layout_marginTop="59dp"
android:layout_alignLeft="@+id/etEntrate"
android:layout_alignStart="@+id/etEntrate"
android:layout_alignRight="@+id/etEntrate"
android:layout_alignEnd="@+id/etEntrate" />
<!--other elements-->
</RelativeLayout>
</LinearLayout>
这里有两张图片,展示了我如何在我的设备上看到 FAB 以及它在模拟器上的样子:
我设备上的 FAB:
FAB 关于 Android Studio 的设计视图
有没有人对此有所了解?谢谢!
当然,FAB 宽度和高度设置为 wrap_content
,但您试图同时向左和向右对齐,这就是它拉伸的原因。
只需删除其中一个即可。
当您在水平方向使用重力时,您必须使用 layout_width=0dp & 在垂直方向的情况下,layout_height=0dp 用于布局中的每个子项。
或
只需从相对布局中删除浮动操作按钮,因为您已经在使用坐标布局。
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coor"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/relative"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="@dimen/activity_horizontal_margin"
android:layout_weight="0.88">
<!-- Other elements-->
<!-- Parent element-->
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/etEntrate"
android:textSize="@dimen/subtitles"
android:padding="@dimen/activity_horizontal_margin"
android:layout_alignRight="@+id/data"
android:layout_alignEnd="@+id/data"
android:layout_below="@+id/etSpese"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:layout_marginEnd="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/activity_horizontal_margin"
android:layout_marginBottom="@dimen/activity_horizontal_margin"/>
<!--FAB-->
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:clickable="true"
app:srcCompat="@drawable/plus"
android:layout_alignTop="@+id/etEntrate"
android:layout_marginTop="59dp"
android:layout_alignLeft="@+id/etEntrate"
android:layout_alignStart="@+id/etEntrate"
android:layout_alignRight="@+id/etEntrate"
android:layout_alignEnd="@+id/etEntrate" />
<!--other elements-->
</RelativeLayout>