如何将 ImageView 固定到布局的底部?

发布于 2024-12-13 14:20:13 字数 135 浏览 4 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

回眸一笑 2024-12-20 14:20:13

请发布您的布局代码。出于多种原因,我强烈建议不要使用relativelayout。通常,您的视图中还有一些其他组件想要占用其余的空间,如果您提供该layout_weight,如另一个答案中提到的,这将解决您的问题。

例如,这将始终将您想要的内容放在底部:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:orientation="vertical">

    <ListView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1">
        <!-- fills the area -->
    </ListView>


    <ImageView
            android:id="@+id/imageNew"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/icon"/>

</LinearLayout>

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:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:orientation="vertical">

    <ListView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1">
        <!-- fills the area -->
    </ListView>


    <ImageView
            android:id="@+id/imageNew"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/icon"/>

</LinearLayout>
心是晴朗的。 2024-12-20 14:20:13

试试这个:

android:layout_alignParentBottom="true"

Try this:

android:layout_alignParentBottom="true"
怪我入戏太深 2024-12-20 14:20:13

你为什么使用 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.

风苍溪 2024-12-20 14:20:13

您必须使用相对布局。

<ImageView 
      ......
      android:layout_alignParentBottom="true">

You have to use a Relativelayout.

<ImageView 
      ......
      android:layout_alignParentBottom="true">

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文