RelativeLayout不能居中的解決的方法


在LinearLayout中有個讓元素居中的辦法就是。比方在LinearLayout里有個TextView.設置TextView的gravity能夠讓其居中。

而在Realative里設置這個不起作用。困擾了我挺長時間。事實上在Realative里有個替代的方法。就是設置子組件的android:layout_centerHorizontal="true"

就ok了。

如:

<RelativeLayout android:layout_width="match_parent" android:layout_height="200dp"
        android:id="@+id/cc_item_topLayout" >
        <ImageView android:layout_width="50dp" android:layout_height="50dp"  android:id="@+id/cc_item_avatar"
            android:src="@drawable/touxiang" android:background="@drawable/btn_myborder" 
            android:layout_marginTop="30dp" android:layout_centerHorizontal="true"
            />
    </RelativeLayout>




免責聲明!

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



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