I need to center an ImageView and TextView inside a RelativeLayout. I can't figure out what I'm doing wrong.
Here is my code:
<RelativeLayout
android:id="@+id/teamNameLayout"
android:layout_width="130dip"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:background="@drawable/border"
android:layout_toLeftOf="@+id/teamPosition"
>
<ImageView
android:id="@+id/teamIcon"
android:src="@drawable/logo1"
android:layout_width="20dip"
android:layout_height="fill_parent"
android:scaleType="fitXY"
android:textStyle="bold"
android:textSize="16sp"
/>
<TextView android:id="@+id/teamName"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:textColor="#000000"
android:textStyle="bold"
android:textSize="16sp"
android:text="blabla" />
</RelativeLayout>
I've tried the "center_horizontal" with no success. I need the ImageView will be to the right of the TextView.
RelativeLayout attributes You can change layout_align parent like top, left, and right. android:layout_centerHorizontal : This attribute is used to center the element horizontally within its parent container. You can change layout_center like layout_centerVertical or layout_centerInParent .
If you have the choice start with ConstraintLayout, but if you already have your app in RelativeLayout, stay with it. That's all I have been following. RelativeLayout is very limited in functionality and many complex layouts can't be made using it, especially when ratios are involved.
We can use LinearLayout inside RelativeLayout. We can also use RelativeLayout as a Child of LinearLayout.
I've tried the "center_horizontal" with no success. I need the ImageView will be to the right of the TextView.
=> Try android:layout_centerInParent="true"
for your TextView, and use android:layout_toRightOf="@+id/teamName
in your ImageView.
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