更多Android布局给android新手带来困扰。我一直在努力学习android编程,而且大多数情况下它很容易(ish),最难的部分就是布局。我现在有一个Tab布局,这是“家庭”视图,并在该视图上我需要一个浮动操作按钮。出于某种原因,悬浮动作按钮占据了屏幕的整个宽度。按钮本身是正确的大小,但是布局会切断屏幕的底部。我遵循了几个教程,不管我做什么,它总是将整个宽度切掉我的屏幕底部。在Android Studio的模拟器中运行的附件截图。 布局是这里...FloatingActionButton正在占用屏幕的宽度
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="com.google.firebase.quickstart.auth.HomeActivity"
android:orientation="vertical">
<!--<android.support.design.widget.AppBarLayout-->
<!--android:id="@+id/appbar"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="wrap_content"-->
<!--android:paddingTop="8dp"-->
<!--android:theme="@style/AppTheme.AppBarOverlay">-->
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay">
</android.support.v7.widget.Toolbar>
<!--</android.support.design.widget.AppBarLayout>-->
<android.support.v4.view.ViewPager
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@color/white"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:scaleType="center"
android:padding="8dp"
android:layout_gravity="bottom|end"
android:layout_margin="8dp"
android:elevation="8dp"
android:tint="@color/white"
app:srcCompat="@drawable/ic_add"/>
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/primaryLightColor" />
</LinearLayout>
我填充片段和这样的观点,但我不认为这是问题。任何人都可以看到为什么FloatingActionButton不是浮动的,而是充当线性布局?十分感谢你的帮助。
只是尝试我不确定完美的结果,但请让我知道它是否有效。在你floatingActionButton只是使** scaleType作为centreCrop **,然后看看它是否有效 –
@AlokKumarVerma它没有工作,仍然显示整个屏幕上的按钮。谢谢 –