Android layout 滚动视图上的Android浮动按钮

Android layout 滚动视图上的Android浮动按钮,android-layout,Android Layout,我必须在固定位置(右上角)放置一个按钮,这样当我滚动屏幕/视图时,按钮始终可见。它就像一个按钮漂浮在视图上。该按钮在滚动视图上始终可见。我猜您正在使用xml文件定义布局。然后需要在ScrollView定义之外定义按钮,例如: <ScrollView ...> ... </ScrollView> <Button ...> </Button> ... 我猜您是在使用xml文件定义布局。然后需要在ScrollView定义之外

我必须在固定位置(右上角)放置一个按钮,这样当我滚动屏幕/视图时,按钮始终可见。它就像一个按钮漂浮在视图上。该按钮在滚动视图上始终可见。

我猜您正在使用xml文件定义布局。然后需要在ScrollView定义之外定义按钮,例如:

<ScrollView
    ...>

    ...
</ScrollView>

<Button
   ...>
</Button>

...

我猜您是在使用xml文件定义布局。然后需要在ScrollView定义之外定义按钮,例如:

<ScrollView
    ...>

    ...
</ScrollView>

<Button
   ...>
</Button>

...

您应该有一个相对的布局。在布局内部,您将有一个滚动视图来填充父级的高度和宽度,按钮也将位于布局内部,但它将与父级顶部对齐为true


这就是答案,如果您有任何问题再次询问

您应该有一个相对布局。在布局内部,您将有一个滚动视图来填充父级的高度和宽度,按钮也将位于布局内部,但它将与父级顶部对齐为true


这就是答案,如果您有任何问题,请再次询问

我制作了一个虚拟应用程序,它可以正常工作 这是布局图

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <RelativeLayout android:layout_width="match_parent" android:id="@+id/relativeLayout1" android:layout_height="wrap_content">
        <ScrollView android:id="@+id/scrollView1" android:layout_height="fill_parent" android:layout_width="fill_parent">
            <LinearLayout android:id="@+id/linearLayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical">
                <RatingBar android:id="@+id/ratingBar1" android:layout_width="wrap_content" android:layout_weight="1" android:layout_height="wrap_content"></RatingBar>
                <Spinner android:layout_width="wrap_content" android:id="@+id/spinner1" android:layout_weight="1" android:layout_height="wrap_content"></Spinner>
                <Spinner android:layout_width="wrap_content" android:id="@+id/spinner2" android:layout_height="wrap_content" android:layout_weight="1"></Spinner>
                <SeekBar android:id="@+id/seekBar1" android:layout_height="wrap_content" android:layout_weight="1" android:layout_width="match_parent"></SeekBar>
                <QuickContactBadge android:layout_width="wrap_content" android:id="@+id/quickContactBadge1" android:layout_weight="1" android:layout_height="wrap_content"></QuickContactBadge>
                <RatingBar android:id="@+id/ratingBar2" android:layout_width="wrap_content" android:layout_weight="1" android:layout_height="wrap_content"></RatingBar>
                <RadioGroup android:layout_width="wrap_content" android:id="@+id/radioGroup1" android:layout_weight="1" android:layout_height="wrap_content">
                    <RadioButton android:text="RadioButton" android:layout_width="wrap_content" android:id="@+id/radio0" android:layout_height="wrap_content" android:checked="true"></RadioButton>
                    <RadioButton android:text="RadioButton" android:layout_width="wrap_content" android:id="@+id/radio1" android:layout_height="wrap_content"></RadioButton>
                    <RadioButton android:text="RadioButton" android:layout_width="wrap_content" android:id="@+id/radio2" android:layout_height="wrap_content"></RadioButton>
                </RadioGroup>
                <Spinner android:layout_width="match_parent" android:id="@+id/spinner3" android:layout_height="wrap_content" android:layout_weight="1"></Spinner>
                <TextView android:layout_width="wrap_content" android:id="@+id/textView1" android:layout_height="wrap_content" android:layout_weight="1" android:text="TextView" android:textAppearance="?android:attr/textAppearanceMedium"></TextView>
                <Button android:layout_width="wrap_content" android:text="Button" android:layout_height="wrap_content" android:layout_weight="1" android:id="@+id/button2"></Button>
                <ProgressBar android:layout_width="wrap_content" android:layout_weight="1" android:id="@+id/progressBar1" android:layout_height="wrap_content" style="?android:attr/progressBarStyleHorizontal"></ProgressBar>
                <RatingBar android:id="@+id/ratingBar3" android:layout_width="wrap_content" android:layout_weight="1" android:layout_height="wrap_content"></RatingBar>
                <QuickContactBadge android:layout_width="wrap_content" android:id="@+id/quickContactBadge2" android:layout_weight="1" android:layout_height="wrap_content"></QuickContactBadge>
                <Button android:layout_width="wrap_content" android:text="Button" android:layout_height="wrap_content" android:layout_weight="1" android:id="@+id/button3"></Button>
                <CheckBox android:layout_width="wrap_content" android:text="CheckBox" android:id="@+id/checkBox1" android:layout_height="wrap_content" android:layout_weight="1"></CheckBox>
            </LinearLayout>
        </ScrollView>
        <Button android:layout_height="wrap_content" android:text="Button" android:layout_width="wrap_content" android:id="@+id/button1"></Button>
    </RelativeLayout>
</LinearLayout>

我制作了一个虚拟应用程序,它可以正常工作 这是布局图

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <RelativeLayout android:layout_width="match_parent" android:id="@+id/relativeLayout1" android:layout_height="wrap_content">
        <ScrollView android:id="@+id/scrollView1" android:layout_height="fill_parent" android:layout_width="fill_parent">
            <LinearLayout android:id="@+id/linearLayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical">
                <RatingBar android:id="@+id/ratingBar1" android:layout_width="wrap_content" android:layout_weight="1" android:layout_height="wrap_content"></RatingBar>
                <Spinner android:layout_width="wrap_content" android:id="@+id/spinner1" android:layout_weight="1" android:layout_height="wrap_content"></Spinner>
                <Spinner android:layout_width="wrap_content" android:id="@+id/spinner2" android:layout_height="wrap_content" android:layout_weight="1"></Spinner>
                <SeekBar android:id="@+id/seekBar1" android:layout_height="wrap_content" android:layout_weight="1" android:layout_width="match_parent"></SeekBar>
                <QuickContactBadge android:layout_width="wrap_content" android:id="@+id/quickContactBadge1" android:layout_weight="1" android:layout_height="wrap_content"></QuickContactBadge>
                <RatingBar android:id="@+id/ratingBar2" android:layout_width="wrap_content" android:layout_weight="1" android:layout_height="wrap_content"></RatingBar>
                <RadioGroup android:layout_width="wrap_content" android:id="@+id/radioGroup1" android:layout_weight="1" android:layout_height="wrap_content">
                    <RadioButton android:text="RadioButton" android:layout_width="wrap_content" android:id="@+id/radio0" android:layout_height="wrap_content" android:checked="true"></RadioButton>
                    <RadioButton android:text="RadioButton" android:layout_width="wrap_content" android:id="@+id/radio1" android:layout_height="wrap_content"></RadioButton>
                    <RadioButton android:text="RadioButton" android:layout_width="wrap_content" android:id="@+id/radio2" android:layout_height="wrap_content"></RadioButton>
                </RadioGroup>
                <Spinner android:layout_width="match_parent" android:id="@+id/spinner3" android:layout_height="wrap_content" android:layout_weight="1"></Spinner>
                <TextView android:layout_width="wrap_content" android:id="@+id/textView1" android:layout_height="wrap_content" android:layout_weight="1" android:text="TextView" android:textAppearance="?android:attr/textAppearanceMedium"></TextView>
                <Button android:layout_width="wrap_content" android:text="Button" android:layout_height="wrap_content" android:layout_weight="1" android:id="@+id/button2"></Button>
                <ProgressBar android:layout_width="wrap_content" android:layout_weight="1" android:id="@+id/progressBar1" android:layout_height="wrap_content" style="?android:attr/progressBarStyleHorizontal"></ProgressBar>
                <RatingBar android:id="@+id/ratingBar3" android:layout_width="wrap_content" android:layout_weight="1" android:layout_height="wrap_content"></RatingBar>
                <QuickContactBadge android:layout_width="wrap_content" android:id="@+id/quickContactBadge2" android:layout_weight="1" android:layout_height="wrap_content"></QuickContactBadge>
                <Button android:layout_width="wrap_content" android:text="Button" android:layout_height="wrap_content" android:layout_weight="1" android:id="@+id/button3"></Button>
                <CheckBox android:layout_width="wrap_content" android:text="CheckBox" android:id="@+id/checkBox1" android:layout_height="wrap_content" android:layout_weight="1"></CheckBox>
            </LinearLayout>
        </ScrollView>
        <Button android:layout_height="wrap_content" android:text="Button" android:layout_width="wrap_content" android:id="@+id/button1"></Button>
    </RelativeLayout>
</LinearLayout>

伙计们,我知道这是一篇老文章仅供参考,谷歌已经推出了一个库来支持很多很酷的东西,比如浮动按钮等,值得一看。

伙计们,我知道这是一篇老文章仅供参考,谷歌已经推出了一个库来支持很多很酷的东西,比如浮动按钮等,值得一看。

你好,卢卡普,谢谢你的回复。该按钮实际上浮动在滚动视图上,即它在顶部位置与视图重叠。如果我按照你说的去做,滚动将发生在按钮下面,我希望按钮在滚动视图中始终可见。你没有完全按照我说的去做:),将按钮和滚动视图都放在相对布局中,为按钮定义align with parent top为true,为scrollviewHi Lukap填充parent,感谢您的回复。该按钮实际上浮动在滚动视图上,即它在顶部位置与视图重叠。如果我按照你说的去做,滚动将发生在按钮下面,我希望按钮在滚动视图上始终可见。你没有完全按照我说的去做:),将按钮和滚动视图都放在相对布局中,为按钮定义“与父视图顶部对齐”为true,为滚动视图填充父视图