DongDong
DongDong

Reputation: 57

How to set ImageView center when I add DrawerToggle?

When I added DrawerToggle(Hamburger) by using kotlin, the ImageView (TravelPocket) moved to right.

So, it is not in center..

I want to make it move to center not using margin or padding property.

below is my image.

problem image

activity_main.xml

<androidx.drawerlayout.widget.DrawerLayout
    android:id="@+id/drawer"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="48dp">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:layout_alignParentTop="true"
            android:background="@color/colorPrimary"
            app:contentInsetStart="0dp">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">
                <ImageView
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:paddingTop="8dp"
                    android:paddingBottom="14dp"
                    android:src="@drawable/ic_logo"/>
            </RelativeLayout>

        </androidx.appcompat.widget.Toolbar>
</RelativeLayout>

MainActivity.class

class MainActivity : AppCompatActivity() {
    lateinit var drawerToggle: ActionBarDrawerToggle
    var currentTime: Long = 0

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)


        drawerToggle = ActionBarDrawerToggle(this, drawer, toolbar,0,0)
        drawer.addDrawerListener(drawerToggle)
        drawerToggle.syncState()

    }
}

Upvotes: 0

Views: 57

Answers (0)

Related Questions