Centering Component RelativeLayout (CCR)


CCR:   SOLD       




Hi dev, initially I tried to do centering component button by calling gravity and orientation attributes, but it didn't work, then with a little force I tried to connect each side of the button with the closest possible elements, but the results were less than optimal. Finally, because there was still a lot of spare time, I took out the google fu trick and it turned out that the Android SDK already provides a facility to do that.

The facility I mean is this attribute.

android:layout_centerHorizontal="true"

Usage example.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:background="#ff0000">

    <Button
        android:id="@+id/btn_mybutton"
        android:layout_height="wrap_content"
        android:layout_width="124dip"
        android:layout_marginTop="5dip"
        android:layout_centerHorizontal="true"/>

</RelativeLayout>

Great!


Post a Comment

Previous Next

نموذج الاتصال