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删除。



猜您在找 RelativeLayout.addRule()方法 Android中RelativeLayout的字符水平(垂直居中)对齐