【问题标题】:How to place fixed button below listview?如何在列表视图下方放置固定按钮?
【发布时间】:2023-03-07 06:02:02
【问题描述】:

有没有办法让一个按钮直接位于列表视图下方,这样随着列表视图的增长,按钮会向下移动,但按钮永远不会被推离屏幕。 IE,一旦列表视图超出屏幕,按钮仍然可见,并且列表视图是可滚动的。

我设法使按钮始终位于屏幕底部,但我希望它直接位于列表视图下方,而列表视图小于屏幕。

我尝试过使用相对和线性布局的各种排列方式并使用 weight 属性,但看起来它们应该工作的东西根本不工作,所以在发布之前可能值得检查任何答案。

澄清: 换一种说法:我希望一个按钮位于列表视图下方,随着它的增长向下移动,但我不希望按钮被推到屏幕外

【问题讨论】:

  • 你看了吗:stackoverflow.com/questions/5487552/…。解决方案试图做的是让按钮始终位于列表底部,但是当它超出屏幕时,它的高度会受到重量的限制。
  • 是的!这行得通,令人难以置信!我的布局现在完全荒谬(imgur.com/c9L1Z queue inception 配乐......)因此我从未尝试过这个解决方案。感谢您指出这一点。
  • 用该评论回答并投票给你作为答案。
  • 很高兴听到这个消息。生病添加它作为答案。事实上,即使我也很好奇这是怎么做到的。

标签: android android-layout


【解决方案1】:

这个previous post 完全符合您的要求。它的基本作用是将按钮始终保持在列表的底部。但是当列表超出屏幕区域时,它的高度会受到weight 参数的限制。
这样,列表的底部边缘就在按钮的 LinearLayout 上方,并且您会得到与您所寻找的相同的行为。

【讨论】:

【解决方案2】:

如果您想在列表项的末尾显示此按钮。然后使用这段代码

final Button btnAddMore = new Button(this);
btnAddMore.setText(R.string.art_btn_moreIssues);
exArticlesList = (ExpandableListView) this.findViewById(R.id.art_list_exlist);
exArticlesList.addFooterView(btnAddMore);

或者,如果您在布局末尾显示按钮,则使用此代码。

<RelativeLayout
android:id="@+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ListView
    android:id="@+id/listView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_above="@+id/btn_New" >
</ListView>

<Button
    android:id="@+id/btn_New"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:layout_marginBottom="20dp"
    android:text="@string/New"
    android:width="170dp"
    android:layout_alignParentBottom="true" />
  </RelativeLayout>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-11
    • 1970-01-01
    • 1970-01-01
    • 2020-03-30
    • 1970-01-01
    • 2015-09-24
    • 2016-05-22
    相关资源
    最近更新 更多