Android 后面的空框架布局块按钮
正如您所看到的,backButton位于框架布局的后面 但是我想让这个按钮可以点击,除非它是可见的 我正在使用scrollview,这意味着我不能在上面放置BackButton。 因为当我向上滚动时,它会落下 这里是XMLAndroid 后面的空框架布局块按钮,android,button,imagebutton,android-framelayout,Android,Button,Imagebutton,Android Framelayout,正如您所看到的,backButton位于框架布局的后面 但是我想让这个按钮可以点击,除非它是可见的 我正在使用scrollview,这意味着我不能在上面放置BackButton。 因为当我向上滚动时,它会落下 这里是XML <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="230dp"
android:src="@drawable/background"
android:scaleType="centerCrop">
</ImageView>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/backButton"
android:clickable="true"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentTop="true"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:src="@drawable/ic_arrow_back_white"/>
</FrameLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="100dp"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="1">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.74"
android:descendantFocusability="blocksDescendants">
//SOME CONTENT HERE, REMOVED FOR READABILITY
</FrameLayout>
</LinearLayout>
</ScrollView>
</FrameLayout>
//此处有些内容已删除,以便于阅读
简单的问题。怎么做?让您的覆盖框架不要自定义触摸事件,让您的下方按钮能够处理触摸事件。因此它是可点击的。这里的问题似乎是,您的
框架布局中既没有一个孩子,也没有使用“android:layout\u gravity”属性。请参阅:
FrameLayout设计用于在屏幕上屏蔽一个区域以显示单个项目。通常,FrameLayout应用于保存单个子视图,因为很难以可扩展到不同屏幕大小的方式组织子视图,而不会使子视图相互重叠。但是,您可以将多个子视图添加到F使用android:layout\u gravity属性,通过为每个子级指定重力,来控制它们在FrameLayout中的位置
从您上传的图片中,我可以看到,使用Android中的新支持库可以轻松实现整个布局
如果是这种情况,整个布局可以转换为使用坐标布局
,而不是直接使用框架布局
。检查以下图像。如果这是您想要的,则继续操作,如果不完全是您想要的,则可以忽略此答案:
如果您想要这样的东西,那么FrameLayout
可能是一条艰难的道路,因为现有的支持设计库将使您的工作更轻松
在这种情况下,它的CoordinatorLayout
和折叠工具栏
,但即使您不想要折叠工具栏,协调器布局仍然是最好的选择
如果您想了解更多关于支持设计库的信息,那么这里有一篇文章。
协调器布局很容易使布局像您的一样,这是一个聪明的选择,因为我上传的图像代码如下:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.sample.foo.usingcoordinatorlayout.FabAndSnackbarActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBar"
android:layout_width="match_parent"
android:layout_height="300dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsingToolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp"
app:title="@string/collapsing_toolbar">
<ImageView
android:id="@+id/toolbarImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:fitsSystemWindows="true"
android:src="@drawable/bg"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_collapseMode="pin" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="28sp"
android:lineSpacingExtra="8dp"
android:text="@string/long_latin"
android:padding="@dimen/activity_horizontal_margin" />
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_margin="@dimen/activity_horizontal_margin"
android:src="@drawable/mascot_icon"
app:layout_anchor="@id/appBar"
app:layout_anchorGravity="bottom|end" />
</android.support.design.widget.CoordinatorLayout>
关于所有这些!请始终记住,您将始终像appcompat一样在app.gradle文件中添加支持设计。但是这些链接中的描述将包含所有这些信息。快乐编码!最简单的方法是将包含您的按钮的框架布局
放在滚动视图之后e> 。框架布局应包装其所包含的内容!将XML文件发布为well@KulsDroid在您需要时添加了XMLsaid@Xenolion很抱歉,我忘了提到这是ScrollView使用RelativeLayout而不是FrameLayout怎么样?它仍然不起作用是的,这将是一个选项。您还可以(每个)您的“FrameLayout”只有一个孩子,只需将内部包装到另一个布局中,例如“RelativeLayout”。您还做了什么?