Android плавающая кнопка над прокруткой - PullRequest
1 голос
/ 21 сентября 2011

Мне нужно поставить кнопку в фиксированном положении (вверху справа), чтобы при прокрутке экрана / вида кнопка всегда была видна.Это как кнопка, плавающая над видом.Кнопка постоянно отображается над видом прокрутки.

Ответы [ 4 ]

4 голосов
/ 22 сентября 2011

Я сделал фиктивное приложение, и оно работает, вот макет

<?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>
2 голосов
/ 21 сентября 2011

Вы должны иметь относительное расположение.Внутри макета у вас будет вид прокрутки, чтобы заполнить родительский элемент как по высоте, так и с помощью кнопки, и кнопка также будет внутри макета, но она будет выровнена с родительской вершиной в значение true ...

это ответ,если у вас есть какие-либо вопросы, задавайте еще раз

0 голосов
/ 27 августа 2015

Ребята, я знаю, что это старый пост, только к вашему сведению, Google разработал библиотеку для поддержки множества интересных вещей, таких как кнопки с плавающей точкой и т. Д. Стоит посмотреть. Служба поддержки Google Design Lib

0 голосов
/ 21 сентября 2011

Я полагаю, вы используете XML-файлы для определения вашего макета.Затем вам нужно определить кнопку вне определения ScrollView, например:

<ScrollView
    ...>

    ...
</ScrollView>

<Button
   ...>
</Button>
...