[英]How to fix an ImageView to the bottom of a Layout?
我有一個FrameLayout,里面有一個垂直的LinearLayout。 我有一個ImageView,我想坐在我的布局的最底部。 我不知道該怎么做。 我將它添加為我的LinearLayout中的最后一個元素,但它沒有固定到底部。 我怎樣才能做到這一點?
請發布您的布局代碼。 出於多種原因,我強烈建議不要使用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>
嘗試這個:
android:layout_alignParentBottom="true"
你為什么使用LinearLayout? 您可以使用RelativeLayout並執行Eng Fouad所說的內容。 但是,如果你真的想使用LinearLayout,你可以使用android:layout_weight使剩下的視圖占用剩余的空間,這樣你的最后一個視圖就會被迫到底。 甚至可能添加一個虛擬視圖,它只占用最后一個視圖之前的所有空間,並顯示空白背景或類似的東西。
你必須使用Relativelayout。
<ImageView
......
android:layout_alignParentBottom="true">
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.