在模拟器上找不到浮动操作按钮
Floating action button cannot be found on emulator
我创建了一个带有 ImageView
、VideoView
和浮动操作按钮的布局。我的想法是继续在 VideoView
和 ImageView
上方显示浮动操作按钮。
下面是我的 XML 代码,看起来浮动操作按钮隐藏在 ImageView
和 VideoView
后面。任何帮助将不胜感激。
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000000"
android:contentDescription="@string/app_name"
android:id="@+id/frame"
tools:context="com.serv24.eframe.FullscreenActivity" >
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|left"
android:visibility="visible"
tools:visibility="visible" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:src="@android:drawable/ic_dialog_email"
android:visibility="visible"
app:backgroundTint="@android:color/holo_red_dark"
app:rippleColor="?android:attr/colorActivatedHighlight" />
<VideoView
android:id="@+id/videoView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical|center_horizontal"
android:visibility="invisible" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical|center_horizontal"
android:contentDescription="@string/app_name"
android:visibility="visible" />
</FrameLayout>
我建议使用 RelativeLayout
而不是 FrameLayout
以便在您的情况下更容易实施。您只需将元素放在其他元素下方,即可在布局中位于上方元素之上。我正在使用 RelativeLayout
分享您的布局版本。希望对您有所帮助!
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/frame"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000000">
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true" />
<VideoView
android:id="@+id/videoView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="invisible" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@string/app_name" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_margin="16dp"
android:src="@android:drawable/ic_dialog_email"
android:visibility="visible"
app:backgroundTint="@android:color/holo_red_dark"
app:rippleColor="?android:attr/colorActivatedHighlight" />
</RelativeLayout>
添加到您的 FrameLayout 中的项目是相互叠加的,因此最新添加的项目在之前添加的项目之上。
在您的情况下,您首先添加了 ProgressBar,然后添加了显示在 ProgressBar 上方的 FloatingActionButton,然后添加了显示在 FloatingActionButton 上方的 VideoView(如果 VideoView 已满screen 它将隐藏您之前放置的所有内容),最后是显示在其他所有内容之上的 ImageView。
您可以将其想象成将纸张叠放在 table 上。
因此,要显示您的 fab,您应该将其放在 xml 中的最后一个位置(在 ImageView 之后)。
我创建了一个带有 ImageView
、VideoView
和浮动操作按钮的布局。我的想法是继续在 VideoView
和 ImageView
上方显示浮动操作按钮。
下面是我的 XML 代码,看起来浮动操作按钮隐藏在 ImageView
和 VideoView
后面。任何帮助将不胜感激。
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000000"
android:contentDescription="@string/app_name"
android:id="@+id/frame"
tools:context="com.serv24.eframe.FullscreenActivity" >
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|left"
android:visibility="visible"
tools:visibility="visible" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:src="@android:drawable/ic_dialog_email"
android:visibility="visible"
app:backgroundTint="@android:color/holo_red_dark"
app:rippleColor="?android:attr/colorActivatedHighlight" />
<VideoView
android:id="@+id/videoView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical|center_horizontal"
android:visibility="invisible" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical|center_horizontal"
android:contentDescription="@string/app_name"
android:visibility="visible" />
</FrameLayout>
我建议使用 RelativeLayout
而不是 FrameLayout
以便在您的情况下更容易实施。您只需将元素放在其他元素下方,即可在布局中位于上方元素之上。我正在使用 RelativeLayout
分享您的布局版本。希望对您有所帮助!
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/frame"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000000">
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true" />
<VideoView
android:id="@+id/videoView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="invisible" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@string/app_name" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_margin="16dp"
android:src="@android:drawable/ic_dialog_email"
android:visibility="visible"
app:backgroundTint="@android:color/holo_red_dark"
app:rippleColor="?android:attr/colorActivatedHighlight" />
</RelativeLayout>
添加到您的 FrameLayout 中的项目是相互叠加的,因此最新添加的项目在之前添加的项目之上。
在您的情况下,您首先添加了 ProgressBar,然后添加了显示在 ProgressBar 上方的 FloatingActionButton,然后添加了显示在 FloatingActionButton 上方的 VideoView(如果 VideoView 已满screen 它将隐藏您之前放置的所有内容),最后是显示在其他所有内容之上的 ImageView。
您可以将其想象成将纸张叠放在 table 上。
因此,要显示您的 fab,您应该将其放在 xml 中的最后一个位置(在 ImageView 之后)。