androidandroid-layoutandroid-imagebuttonandroiddesignsupportandroid-layout-editor

Align ImageButton right inside Tablerow


enter image description here

I want my imagebutton to be aligned right but as you can see its left aligned even when the gravity="right". This is my file:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:app="http://schemas.android.com/apk/res-auto"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:orientation="horizontal"
 >

<TableRow android:layout_height="20dp">


    <ImageButton
        android:id="@+id/imageButton2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:backgroundTint="@android:color/transparent"
        android:graviy="right"
        app:srcCompat="@drawable/ic_person_black_24dp" />
</TableRow>

</TableLayout>

How can I align my imagebutton right? I though gravity="right" would solve the problem? I tryied layout_gravity and gravity. Both dont work


Solution

  • First of all, you have graviy instead of gravity.
    gravity attribute specifies "how are my children aligned inside of me" - eg. text inside TextView, Views inside Layout. layout_gravity tells parent "how I want to be positioned". Not all layouts pay respect to layout_gravity of their children, in this case setting gravity="end" to your TableRow works. You can remove both gravity and layout_gravity from ImageButton.