Android -如何在底部左對齊,中對齊,右對齊三個按鈕圖片 巧用Relative Layout


Relative Layout 不僅可以指定同級的元素之間的位置關系(e.g. layout_toLeftOf) 還可以指定子元素與父元素之間的位置關系(e.g. layout_alignParentLeft 相對於父元素左對齊) 利用這一點,可以輕松實現圖片在屏幕底部對齊顯示。 

代碼如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:divider="@drawable/line"
android:showDividers="middle">

<!--新聞內容 -->
<WebView
android:id="@+id/web"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">

</WebView>

<!--底部圖片-->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
>

<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="10dp"
android:layout_alignParentLeft="true"<!--在父元素中左對齊 -->
android:background="@drawable/back" />

<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_centerInParent="true"<!--在父元素中居中對齊 -->
android:background="@drawable/house" />

<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/share"
android:layout_alignParentRight="true" <!--在父元素中右對齊 -->
android:layout_marginRight="10dp"
android:layout_gravity="center_horizontal"
/>

</RelativeLayout>


</LinearLayout>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM