Toolbar header's item alignment issue?

前端 未结 4 1061
北荒
北荒 2021-01-25 23:35

Today i have stucked in one of the weird problem in Toolbar custom header.
I am using the TextView in the center and ImageView which i

相关标签:
4条回答
  • 2021-01-25 23:48

    @MikeM. suggestion has worked for me. For more detail on the issue please refer this link click here

    What i have done to get rid off from the problem is that I have removed the LinearLayout inside the Toolbar and set the gravity of the view with help of android:layout_gravity, Please refer the below solution for it

                <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    android:background="#3EC3D6"
                    app:layout_collapseMode="pin"
                    app:popupTheme="@style/AppTheme.NoActionBar.PopupOverlay">
    
                    <TextView
                        android:id="@+id/headerTxt"
                        style="@style/Base.TextAppearance.AppCompat.Medium"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:ellipsize="marquee"
                        android:maxLines="1"
                        android:text="Tile"
                        android:textColor="@android:color/black" />
    
                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="right"
                        android:layout_marginRight="10dp"
                        android:src="@drawable/chat_new_icon" />
    
    
                </android.support.v7.widget.Toolbar>
    

    And getting the expected result from above code, please check it once.

    0 讨论(0)
  • 2021-01-25 23:53

    Just update your code...edited your relative layout implementation

    <RelativeLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal">
    
                        <TextView
                            android:id="@+id/headerTxt"
                            style="@style/Base.TextAppearance.AppCompat.Medium"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:ellipsize="marquee"
                            android:layout_centerInParent="true"
                            android:maxLines="1"
                            android:text="Tile"
                            android:textColor="@android:color/black" />
    
    
                        <ImageView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:src="@drawable/chat_new_icon"
                            android:layout_toRightOf="@+id/headerTxt"
                             android:layout_centerVertical="true"
                            />
    
                    </RelativeLayout>
    
    0 讨论(0)
  • 2021-01-25 23:57

    This is working ...

    <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:local="http://schemas.android.com/tools"
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="#3EC3D6"
        app:layout_collapseMode="pin"
        local:popupTheme="@style/ThemeOverlay.AppCompat.Light">
    
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
    
            <TextView
                android:id="@+id/headerTxt"
                style="@style/Base.TextAppearance.AppCompat.Medium"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:ellipsize="marquee"
                android:maxLines="1"
                android:text="Tile"
                android:textColor="@android:color/black" />
    
    
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_toRightOf="@+id/headerTxt"
                android:src="@drawable/delete_icon" />
    
        </RelativeLayout>
    </android.support.v7.widget.Toolbar>
    
    0 讨论(0)
  • 2021-01-26 00:01

    This is what comes at my end

    <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:local="http://schemas.android.com/tools"
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="#3EC3D6"
        app:layout_collapseMode="pin"
        local:popupTheme="@style/ThemeOverlay.AppCompat.Light">
    
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
    
            <TextView
                android:id="@+id/headerTxt"
                style="@style/Base.TextAppearance.AppCompat.Medium"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:ellipsize="marquee"
                android:maxLines="1"
                android:text="Tile"
                android:textColor="@android:color/black" />
    
    
            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_toRightOf="@+id/headerTxt"
                android:src="@drawable/delete_icon" />
    
        </RelativeLayout>
    </android.support.v7.widget.Toolbar>
    

    0 讨论(0)
提交回复
热议问题