i have some imagebuttons and each one has a corresponding textview, i'd like to align those textview's to the center of their corresponding imageview, i mean, like is seen on the app drawer...
!-----! !icon ! !_____! app name
this is my code, i'm using a RelativeLayout
<ImageButton android:id="@+id/blog_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_below="@+id/logo_img" android:layout_marginLeft="50dp" android:layout_marginTop="51dp" android:background="@null" android:contentDescription="@string/blog_desc" android:src="@drawable/blog" /> <TextView android:id="@+id/blog_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/blog_button" android:layout_below="@+id/blog_button" android:layout_marginTop="8dp" android:text="@string/blog_desc" />
Wrap that in a LinearLayout
and center the children, like so:
<LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/logo_img" android:gravity="center_horizontal" android:orientation="vertical"> <ImageButton android:id="@+id/blog_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@null" android:contentDescription="@string/blog_desc" android:src="@drawable/blog" /> <TextView android:id="@+id/blog_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="@string/blog_desc" /> </LinearLayout>
Old post but if this can help I think it's not necessary to add an additional container.
<ImageButton android:id="@+id/blog_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_below="@+id/logo_img" android:layout_marginLeft="50dp" android:layout_marginTop="51dp" android:background="@null" android:contentDescription="@string/blog_desc" android:src="@drawable/blog" /> <TextView android:id="@+id/blog_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/blog_button" android:layout_alignRight="@+id/blog_button" android:layout_below="@+id/blog_button" android:gravity="center_horizontal" android:layout_marginTop="8dp" android:layout_marginLeft="-20dp" android:layout_marginRight="-20dp" android:text="@string/blog_desc" />
It's work for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With