Android 屏幕上的固定按钮
我正在使用一个滚动视图和一个RelativeLayout。我在屏幕底部有一个按钮我希望按钮在滚动时随屏幕移动。按钮应位于屏幕右下角 我曾尝试使用FrameLayout,如与此问题相关的一个答案中所述,但我希望我的按钮位于屏幕的右下角。 现在,按钮出现在整个屏幕的底部,这意味着您必须向下滚动一点才能看到它Android 屏幕上的固定按钮,android,xml,android-studio,Android,Xml,Android Studio,我正在使用一个滚动视图和一个RelativeLayout。我在屏幕底部有一个按钮我希望按钮在滚动时随屏幕移动。按钮应位于屏幕右下角 我曾尝试使用FrameLayout,如与此问题相关的一个答案中所述,但我希望我的按钮位于屏幕的右下角。 现在,按钮出现在整个屏幕的底部,这意味着您必须向下滚动一点才能看到它 <ScrollView android:layout_height="match_parent" xmlns:android="http://schemas.android
<ScrollView
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:fillViewport="true"
>
<RelativeLayout
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:layout_width="match_parent"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.example.android.app1.SecondScreen">
<TextView
android:text="Check all the Symptoms which apply - "
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25sp"
android:id="@+id/textView" />
<CheckBox1>
<CheckBox2>
<CheckBox3>
<CheckBox4>
<CheckBox5>
<CheckBox6>
<CheckBox7>
<CheckBox8>
<CheckBox9>
<CheckBox10>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25sp"
android:text="submit"
android:id="@+id/submitbutton"
android:layout_below="@id/Lastcheckbox"
android:layout_alignParentRight="true"
/>
</RelativeLayout>
</ScrollView>
如何实现这一点?您需要一个浮动操作按钮:
<RelativeLayout
...
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.design.widget.FloatingActionButton
android:id="@+id/myFAB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_plus_sign"
app:elevation="4dp"
... />
以获得整个工作项目
将Android Studio更新为1.5
创建一个带有空白活动的新项目,它会自动为您生成
使用
FloatingActionBar
而不是屏幕右下角的普通按钮,使用设计支持库
<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:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_dialog_email" />
您可以使用按钮分隔滚动视图
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="match_parent"
android:layout_width="match_parent">
<ScrollView
android:id="@+id/myScrollView"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:fillViewport="true"
android:layout_above="@+id/submitbutton">
<RelativeLayout
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:layout_width="match_parent"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.example.android.app1.SecondScreen">
<TextView
android:text="Check all the Symptoms which apply - "
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25sp"
android:id="@+id/textView" />
<CheckBox1/>
<CheckBox2/>
<CheckBox3/>
<CheckBox4/>
<CheckBox5/>
<CheckBox6/>
<CheckBox7/>
<CheckBox8/>
<CheckBox9/>
<CheckBox10/>
</RelativeLayout>
</ScrollView>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25sp"
android:text="submit"
android:id="@+id/submitbutton"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true" />
</RelativeLayout>
您可以像前面提到的那样使用
浮动操作按钮。
或
您可以将滚动视图
放置在线性布局中
并将按钮放置在滚动视图
之后,如下所示:
<LinearLayout ....>
<ScrollView
android:layout_width=".."
android:layout_height="0"
android:layout_weight="1">
<RelativeLayout>
.
.
.
</RelativeLayout>
</ScrollView>
<Button android:layout_gravity = "right" ..... />
</LinearLayout>
.
.
.
我已经下载了最新的更新,但是现在如何更新?如果您的android studio不是1.4+,请转到“帮助”->“检查更新”。如果你有1.4+版本…那么你就准备好了由android studio生成fab,只需创建一个新的空白项目就可以了我有android 1.2。单击“帮助->检查更新”后,它会要求下载更新。我已经下载了更新。我应该如何继续?让它下载并安装…它会自动重新启动。。。!如何使用appcompat v7库?如果您有此链接,请在此链接获取战利品,只需将库添加到您的dependencies@sathishkumarFloatingActionButton
位于support:design
库中,不在v7中。请更新您的答案您不认为使用LinearLayout会取消将按钮放置在屏幕右侧的选项吗?您可以始终这样做:D
<LinearLayout ....>
<ScrollView
android:layout_width=".."
android:layout_height="0"
android:layout_weight="1">
<RelativeLayout>
.
.
.
</RelativeLayout>
</ScrollView>
<Button android:layout_gravity = "right" ..... />
</LinearLayout>