【发布时间】:2017-01-10 11:43:15
【问题描述】:
我的应用程序中的浮动操作按钮出现了一些问题。在 Android Studio 模拟器中,无论是在应用程序模拟器中的 xml 文件的“设计”视图中,它看起来都不错,但在真实设备中,当我运行应用程序时,它不是圆形,而是椭圆形. 此外,此错误仅在某些执行时发生...昨天 FAB 在我的设备上也是循环的,但今天不是(我没有修改 xml 部分,在 Java 方面我不处理它的方面)...
这是我定义按钮的 .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:
Android Studio设计视图上的FAB
有人对此有所了解吗?谢谢!
【问题讨论】:
-
首先使用
android:src设置FAB 可绘制然后你能告诉我为什么你将它与etEntrate元素的左右对齐吗?画出你想要归档的草稿。咻! -
您使用的是哪个版本的设计支持库?
-
尝试更改页边距。
-
感恩@fillobotto!我读了好几遍,但我从来没有注意到这个愚蠢的错误......现在它是循环的,当然!如果我将 'android:srcCompat' 更改为 'android:src' 我会得到一个“找不到包中属性 src 的资源标识符...”,所以我使用的是 'srcCompat'。如果您回答问题,我可以接受并关闭它
标签: android android-layout floating-action-button