如何将 ImageView 固定到布局的底部?
我有一个 FrameLayout,里面有一个垂直的 LinearLayout。我有一个 ImageView,我想将其放置在布局的最底部。我不知道该怎么做。我将其添加为 LinearLayout 中的最后一个元素,但它并未固定在底部。我怎样才能实现这个目标?
I have a FrameLayout with a vertical LinearLayout inside. I have an ImageView that I want to sit at the very bottom of my layout. I'm not sure how to do this. I added it as the last element in my LinearLayout but it's not fixed to the bottom. How can I achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
请发布您的布局代码。出于多种原因,我强烈建议不要使用relativelayout。通常,您的视图中还有一些其他组件想要占用其余的空间,如果您提供该layout_weight,如另一个答案中提到的,这将解决您的问题。
例如,这将始终将您想要的内容放在底部:
Please post your layout code. I highly recommend not using RelativeLayout, for a number of reasons. usually there is some other component of your view that you'd like to take up the rest of the space, and if you give that layout_weight, as mentioned in another answer, that will solve your problem.
As an example, this will always put what you want at the bottom:
试试这个:
Try this:
你为什么使用 LinearLayout?你可以只使用RelativeLayout并按照Eng Fouad所说的去做。但是,如果您确实想要使用 LinearLayout,则可以使用 android:layout_weight 使其余视图占用剩余空间,以便最后一个视图被迫位于底部。甚至可能添加一个虚拟视图,它仅占据最后一个视图之前的所有空间并显示空白背景或类似的内容。
Why are you using a LinearLayout?? You could just use a RelativeLayout and do what Eng Fouad said. But, if you really want to use a LinearLayout, you can use android:layout_weight to make the rest of the views take up the leftover space so your last view is forced to the bottom. Maybe even add a dummy view that simply takes up all the space before the last view and shows an empty background or something like that.
您必须使用相对布局。
You have to use a Relativelayout.