Android menu Item can not be fit to its parent layout
when action_layout_avl layout is calling its width is fit the parent but when it is included in menu as actionLayout, the width just cover half of the parent page.
below is menu Item:
<?xml version="1.0" encoding="utf-8"?>
<menu 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_gravity="end"
android:gravity="end"
android:layoutDirection="rtl">
<item
android:id="@+id/map_services"
android:title="title">
<menu>
<group>
<item
android:id="@+id/switch_menu_item_poweroff"
android:title=""
app:actionLayout="@layout/action_layout_powwerroff
app:showAsAction="always" />
<item
android:id="@+id/switch_menu_item_avl"
android:title=""
app:actionLayout="@layout/action_layout_avl"
app:showAsAction="always"/>
<item
android:id="@+id/menu_item_routing"
android:icon="@drawable/route"
android:title="@string/label_routing"
app:showAsAction="ifRoom"/>
</group>
</menu>
</item>
</menu>
below is action_layout_avl layout
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:textDirection="ltr"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:gravity="left">
<TextView
android:id="@+id/textavl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:gravity="left"
android:text="AVL"
app:layout_constraintVertical_weight=".6"
app:layout_constraintEnd_toEndOf="parent"/>
<ImageButton
android:id="@+id/buttonAvlFilter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@null"
android:src="@drawable/ic_settings_black_24dp"
app:layout_constraintLeft_toRightOf="@+id/switchAvlWS"
app:layout_constraintRight_toLeftOf="@+id/textavl"
app:layout_constraintTop_toTopOf="parent" />
<Switch
android:id="@+id/switchAvlWS"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOff="خاموش"
android:textOn="روشن"
app:layout_constraintStart_toStartOf="parent"/>
</android.support.constraint.ConstraintLayout>
Normally the behavior of the layout should not change when it is calling
inside menu item.what could be wrong in the code which cause this problem?
Any help can be appreciated
java android-studio layout menu drawerlayout
add a comment |
when action_layout_avl layout is calling its width is fit the parent but when it is included in menu as actionLayout, the width just cover half of the parent page.
below is menu Item:
<?xml version="1.0" encoding="utf-8"?>
<menu 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_gravity="end"
android:gravity="end"
android:layoutDirection="rtl">
<item
android:id="@+id/map_services"
android:title="title">
<menu>
<group>
<item
android:id="@+id/switch_menu_item_poweroff"
android:title=""
app:actionLayout="@layout/action_layout_powwerroff
app:showAsAction="always" />
<item
android:id="@+id/switch_menu_item_avl"
android:title=""
app:actionLayout="@layout/action_layout_avl"
app:showAsAction="always"/>
<item
android:id="@+id/menu_item_routing"
android:icon="@drawable/route"
android:title="@string/label_routing"
app:showAsAction="ifRoom"/>
</group>
</menu>
</item>
</menu>
below is action_layout_avl layout
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:textDirection="ltr"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:gravity="left">
<TextView
android:id="@+id/textavl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:gravity="left"
android:text="AVL"
app:layout_constraintVertical_weight=".6"
app:layout_constraintEnd_toEndOf="parent"/>
<ImageButton
android:id="@+id/buttonAvlFilter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@null"
android:src="@drawable/ic_settings_black_24dp"
app:layout_constraintLeft_toRightOf="@+id/switchAvlWS"
app:layout_constraintRight_toLeftOf="@+id/textavl"
app:layout_constraintTop_toTopOf="parent" />
<Switch
android:id="@+id/switchAvlWS"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOff="خاموش"
android:textOn="روشن"
app:layout_constraintStart_toStartOf="parent"/>
</android.support.constraint.ConstraintLayout>
Normally the behavior of the layout should not change when it is calling
inside menu item.what could be wrong in the code which cause this problem?
Any help can be appreciated
java android-studio layout menu drawerlayout
add a comment |
when action_layout_avl layout is calling its width is fit the parent but when it is included in menu as actionLayout, the width just cover half of the parent page.
below is menu Item:
<?xml version="1.0" encoding="utf-8"?>
<menu 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_gravity="end"
android:gravity="end"
android:layoutDirection="rtl">
<item
android:id="@+id/map_services"
android:title="title">
<menu>
<group>
<item
android:id="@+id/switch_menu_item_poweroff"
android:title=""
app:actionLayout="@layout/action_layout_powwerroff
app:showAsAction="always" />
<item
android:id="@+id/switch_menu_item_avl"
android:title=""
app:actionLayout="@layout/action_layout_avl"
app:showAsAction="always"/>
<item
android:id="@+id/menu_item_routing"
android:icon="@drawable/route"
android:title="@string/label_routing"
app:showAsAction="ifRoom"/>
</group>
</menu>
</item>
</menu>
below is action_layout_avl layout
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:textDirection="ltr"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:gravity="left">
<TextView
android:id="@+id/textavl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:gravity="left"
android:text="AVL"
app:layout_constraintVertical_weight=".6"
app:layout_constraintEnd_toEndOf="parent"/>
<ImageButton
android:id="@+id/buttonAvlFilter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@null"
android:src="@drawable/ic_settings_black_24dp"
app:layout_constraintLeft_toRightOf="@+id/switchAvlWS"
app:layout_constraintRight_toLeftOf="@+id/textavl"
app:layout_constraintTop_toTopOf="parent" />
<Switch
android:id="@+id/switchAvlWS"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOff="خاموش"
android:textOn="روشن"
app:layout_constraintStart_toStartOf="parent"/>
</android.support.constraint.ConstraintLayout>
Normally the behavior of the layout should not change when it is calling
inside menu item.what could be wrong in the code which cause this problem?
Any help can be appreciated
java android-studio layout menu drawerlayout
when action_layout_avl layout is calling its width is fit the parent but when it is included in menu as actionLayout, the width just cover half of the parent page.
below is menu Item:
<?xml version="1.0" encoding="utf-8"?>
<menu 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_gravity="end"
android:gravity="end"
android:layoutDirection="rtl">
<item
android:id="@+id/map_services"
android:title="title">
<menu>
<group>
<item
android:id="@+id/switch_menu_item_poweroff"
android:title=""
app:actionLayout="@layout/action_layout_powwerroff
app:showAsAction="always" />
<item
android:id="@+id/switch_menu_item_avl"
android:title=""
app:actionLayout="@layout/action_layout_avl"
app:showAsAction="always"/>
<item
android:id="@+id/menu_item_routing"
android:icon="@drawable/route"
android:title="@string/label_routing"
app:showAsAction="ifRoom"/>
</group>
</menu>
</item>
</menu>
below is action_layout_avl layout
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:textDirection="ltr"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:gravity="left">
<TextView
android:id="@+id/textavl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:gravity="left"
android:text="AVL"
app:layout_constraintVertical_weight=".6"
app:layout_constraintEnd_toEndOf="parent"/>
<ImageButton
android:id="@+id/buttonAvlFilter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@null"
android:src="@drawable/ic_settings_black_24dp"
app:layout_constraintLeft_toRightOf="@+id/switchAvlWS"
app:layout_constraintRight_toLeftOf="@+id/textavl"
app:layout_constraintTop_toTopOf="parent" />
<Switch
android:id="@+id/switchAvlWS"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOff="خاموش"
android:textOn="روشن"
app:layout_constraintStart_toStartOf="parent"/>
</android.support.constraint.ConstraintLayout>
Normally the behavior of the layout should not change when it is calling
inside menu item.what could be wrong in the code which cause this problem?
Any help can be appreciated
java android-studio layout menu drawerlayout
java android-studio layout menu drawerlayout
edited Feb 11 at 21:26
Amir
asked Nov 22 '18 at 9:53
AmirAmir
161214
161214
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Finally I solved this problem, this issue related to setting title for menu item even the title is empty. It by default allocates half space for the title and icon and another half space for action layout. So, I just remove title and set tools:ignore="MenuTitle".
<group>
<item
android:id="@+id/switch_menu_item_poweroff"
app:actionLayout="@layout/action_layout_powwerroff"
app:showAsAction="always"
tools:ignore="MenuTitle" />
<item
android:id="@+id/switch_menu_item_avl"
app:actionLayout="@layout/action_layout_avl"
app:showAsAction="always"
tools:ignore="MenuTitle" />
<item
android:id="@+id/menu_item_routing"
android:icon="@drawable/route"
android:title="@string/label_routing"
app:showAsAction="ifRoom"
/>
</group>
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53428196%2fandroid-menu-item-can-not-be-fit-to-its-parent-layout%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Finally I solved this problem, this issue related to setting title for menu item even the title is empty. It by default allocates half space for the title and icon and another half space for action layout. So, I just remove title and set tools:ignore="MenuTitle".
<group>
<item
android:id="@+id/switch_menu_item_poweroff"
app:actionLayout="@layout/action_layout_powwerroff"
app:showAsAction="always"
tools:ignore="MenuTitle" />
<item
android:id="@+id/switch_menu_item_avl"
app:actionLayout="@layout/action_layout_avl"
app:showAsAction="always"
tools:ignore="MenuTitle" />
<item
android:id="@+id/menu_item_routing"
android:icon="@drawable/route"
android:title="@string/label_routing"
app:showAsAction="ifRoom"
/>
</group>
add a comment |
Finally I solved this problem, this issue related to setting title for menu item even the title is empty. It by default allocates half space for the title and icon and another half space for action layout. So, I just remove title and set tools:ignore="MenuTitle".
<group>
<item
android:id="@+id/switch_menu_item_poweroff"
app:actionLayout="@layout/action_layout_powwerroff"
app:showAsAction="always"
tools:ignore="MenuTitle" />
<item
android:id="@+id/switch_menu_item_avl"
app:actionLayout="@layout/action_layout_avl"
app:showAsAction="always"
tools:ignore="MenuTitle" />
<item
android:id="@+id/menu_item_routing"
android:icon="@drawable/route"
android:title="@string/label_routing"
app:showAsAction="ifRoom"
/>
</group>
add a comment |
Finally I solved this problem, this issue related to setting title for menu item even the title is empty. It by default allocates half space for the title and icon and another half space for action layout. So, I just remove title and set tools:ignore="MenuTitle".
<group>
<item
android:id="@+id/switch_menu_item_poweroff"
app:actionLayout="@layout/action_layout_powwerroff"
app:showAsAction="always"
tools:ignore="MenuTitle" />
<item
android:id="@+id/switch_menu_item_avl"
app:actionLayout="@layout/action_layout_avl"
app:showAsAction="always"
tools:ignore="MenuTitle" />
<item
android:id="@+id/menu_item_routing"
android:icon="@drawable/route"
android:title="@string/label_routing"
app:showAsAction="ifRoom"
/>
</group>
Finally I solved this problem, this issue related to setting title for menu item even the title is empty. It by default allocates half space for the title and icon and another half space for action layout. So, I just remove title and set tools:ignore="MenuTitle".
<group>
<item
android:id="@+id/switch_menu_item_poweroff"
app:actionLayout="@layout/action_layout_powwerroff"
app:showAsAction="always"
tools:ignore="MenuTitle" />
<item
android:id="@+id/switch_menu_item_avl"
app:actionLayout="@layout/action_layout_avl"
app:showAsAction="always"
tools:ignore="MenuTitle" />
<item
android:id="@+id/menu_item_routing"
android:icon="@drawable/route"
android:title="@string/label_routing"
app:showAsAction="ifRoom"
/>
</group>
answered Nov 24 '18 at 6:17
AmirAmir
161214
161214
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53428196%2fandroid-menu-item-can-not-be-fit-to-its-parent-layout%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown