固定在屏幕底部,不随ScrollView 滚动而改变位置的按钮?怎实现?

蓝色歌谣 2011-06-23 05:02:34



布局文件类似这样:


<?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">

<ScrollView android:layout_width="fill_parent" android:id="@+id/scrollView1"
android:layout_height="wrap_content" android:scrollbars="none">

<LinearLayout android:id="@+id/linearLayout1"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="vertical">

<TextView android:text="动态设置超长的字符串 ... 省略 N 个字,N = 灰常大!" android:id="@+id/textView1"
android:layout_width="wrap_content" android:layout_height="wrap_content">
</TextView>

</LinearLayout>

</ScrollView>


<Button android:gravity="center_horizontal"
android:text="这个Button 要固定在屏幕的底部,不随ScrollView 内容的变化而改变位置,请问如何实现?"
android:id="@+id/button1" android:layout_width="wrap_content"
android:layout_alignParentBottom ="true"
android:layout_marginLeft="10px"
android:layout_height="wrap_content">
</Button>

</LinearLayout>


...全文
3400 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
JackyHuaLei 2011-08-28
  • 打赏
  • 举报
回复
居然这么简单
ch_984326013 2011-06-24
  • 打赏
  • 举报
回复
<LinearLayout>

<ScrollView>

</ScrollView>

</LinearLayout>
这是一种方法!常用的!楼上的好多都可以实现你那效果!呵呵
Nico 2011-06-24
  • 打赏
  • 举报
回复


<RelativeLayout>

<ScrollView>

</ScrollView>
<Button android:layout_alignParentBottom="true"/>

</RelativeLayout>

_DaHuiLang_ 2011-06-24
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 hjue 的回复:]
给scroll添加layout_weight就可以实现,修改后的代码如下

XML code

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"……
[/Quote]

顶3楼,

另外的做法可以是将scrollview的weight设为n,button的weight设为1。
至于n为多少自己斟酌。就可以实现让按钮在底部了
多鱼的夏天 2011-06-23
  • 打赏
  • 举报
回复
给scroll添加layout_weight就可以实现,修改后的代码如下

<?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">

<ScrollView android:layout_width="fill_parent" android:id="@+id/scrollView1"
android:layout_height="wrap_content" android:scrollbars="none" android:layout_weight="1.0">

<LinearLayout android:id="@+id/linearLayout1"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="vertical">

<TextView android:text="动态设置超长的字符串 ... 省略 N 个字,N = 灰常大!" android:id="@+id/textView1"
android:layout_width="wrap_content" android:layout_height="wrap_content">
</TextView>

</LinearLayout>

</ScrollView>


<Button android:gravity="center_horizontal"
android:text="这个Button 要固定在屏幕的底部,不随ScrollView 内容的变化而改变位置,请问如何实现?"
android:id="@+id/button1" android:layout_width="wrap_content"
android:layout_alignParentBottom ="true"
android:layout_marginLeft="10px"
android:layout_height="wrap_content">
</Button>

</LinearLayout>

mahaiyun18 2011-06-23
  • 打赏
  • 举报
回复
android:layout_alignParentBottom="true"
你把button放到layout中,在layout中加入上面的属性,试试~~好像是,不对的话再问我
ryfsoft 2011-06-23
  • 打赏
  • 举报
回复
底部不是有个什么菜单,一直在下面的,可以弄不
因为demo太大请移步github: https://github.com/shabake/GHAlibabaSpecificationSelectionDemoFeatures初始化确定按钮颜色置灰,不可点击。当 spu 颜色数量大于1个时,显示颜色导航,底部列表可以滚动,反之隐藏,布局自适应。如果有颜色导航,输入或点击 + - 按钮,颜色导航对应的颜色数字同步变化,如果数量大于99显示99+;如果数量小于1不显示。点击> < 底部列表和颜色导航同步滚动。输入或点击 + - 按钮,当按 +到最大库存 + 置灰;当按 - 到0 - 置灰。点击输入框。键盘弹出,规格选择器 上移;点击完成,键盘收回,规格选择器 回到原位。点击颜色导航条的颜色标签,高亮被点击颜色标签并滚动屏幕中心,底部列表滑动到对应位置,同时切换 sku 图片。当输入或者点击数量大于1,确定按钮可点击,颜色高亮。当库存不足的时候,输入框下显示库存不足标签。输入框不可输入 0 ,. 。列表行自适应高度,布局中心对齐。点击背景遮罩或者 x ,收回弹窗。动态输入监听,同步显示,根据输入判定确定状态。数据模型重新组装。适配IPhoneX及以上系列。使用demo 数据是从接口获取,需要连接wifi或蜂窝网络。数据结构 (点击箭头展开/收起)GHSpecificationSelectionTitleModel 颜色导航器模型 GHSpecificationSelectionModel sku 模型 GHSpecificationSelectionImageModel 图片模型初始化对象 GHAlibabaSpecificationSelection继承 GHPopView ,GHPopView 已经封装好弹出/收回动画,外部无需重复处理。- (void)show;- (void)dismiss传入数据/*** 数据源* @param skuList 装skuModel数组* @param colors 颜色数组 非必传,如果为空,不显示颜色导航* @param sectePrice 价格区间字典*/[self.alibabaSpecificationSelection setSkuList:specifications colors:colors sectePrice:sectePrice];​取出用户选择_alibabaSpecificationSelection.getDataBlock = ^(NSArray * _Nonnull dataArray) {NSMutableString *string = [NSMutableString string];for (NSDictionary *dict in dataArray) {[string appendFormat:@"颜色:%@ 数量:%@ id:%@",dict[@"color"],dict[@"skuNum"],dict[@"skuId"]];}KAlert(@"用户选择的数据", string);};重置数据在这个方法内部清除所有count。底部scrollview 滚动到初始化状态。底部确定按钮初始化状态。scrollTitles初始化。- (void) resetData;与我联系45329453@qq.com

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧