How to add items to Navigation Drawer Menu Horizontally?












0















enter image description here



The above behaves like an Android Navigation Drawer Menu but written in c++ and I'm trying to replicate it in Android using Navigation Drawer Menu I have achieved it but vertically. This is a part of an app for TV and not for the smart phones. I cannot seem to display the contents in Horizontally is this even possible ? Can someone please help!
This is what I have manged so far;



enter image description here



activity_navigation_drawer.xml



<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
android:id="@+id/nav_drawer">

<ImageView
android:id="@+id/icon"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_marginLeft="1dp"
android:contentDescription="Icons"/>

<TextView
android:id="@+id/titles"
android:layout_width ="90dp"
android:layout_height ="wrap_content"
android:layout_marginLeft ="-40dp"
android:layout_marginTop ="70dp"
android:textColor ="@color/colorPrimary"
android:textSize="16sp"
android:layout_below ="@+id/icon"/>
</LinearLayout>


NavigationAdapter.java



public class NavigationAdapter extends ArrayAdapter<String> {
private final Context context;
private final String titles;
private final int icon;

public NavigationAdapter(Context context, int icon, String titles){
super(context, R.layout.activity_navigation_drawer,titles);
this.context=context;
this.icon = icon;
this.titles = titles;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.activity_navigation_drawer,parent,false);

ImageView imageView=(ImageView)rowView.findViewById(R.id.icon);
TextView textView = (TextView)rowView.findViewById(R.id.titles);

imageView.setImageResource(icon[position]);
textView.setText(titles[position]);

return rowView;
}
}


MainActivity.java



public class MainActivity extends AppCompatActivity {
private ListView mDrawerList1;
private DrawerLayout mDrawerLayout;

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

mDrawerList1 = (ListView) findViewById(R.id.resource_bank);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
addDrawerItems();

navOne = (ImageButton) findViewById(R.id.nav_one);
navOne.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
mDrawerLayout.closeDrawer(GravityCompat.START);
} else {
mDrawerLayout.openDrawer(GravityCompat.START);
}
}
});
}

private void addDrawerItems() {

int icon = {R.drawable.xxx_my_computer,
R.drawable.xxx_my_items,
R.drawable.xxx_favorite,
R.drawable.xxx_remote,
};

String name ={"Computer",
"Items",
"Favorite",
"Remote",
};

NavigationAdapter onAdapter = new NavigationAdapter(MainActivity.this,icon,name);
mDrawerList1.setAdapter(onAdapter);

mDrawerList1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(MainActivity.this, "Resource Bank", Toast.LENGTH_SHORT).show();
}
});
}
}









share|improve this question

























  • set parant LinearLayout android:orientation="vertical"

    – Ali
    Nov 21 '18 at 12:48











  • Thanks but it doesn't work.

    – Tony
    Nov 21 '18 at 12:52











  • Well... I don't think it's possible due the way the Navigator deals with the menu layout. But looking at your example in C++, you can achieve this by setting the buttons in a XML layout and set it to the header of the NavigationView tag.

    – Giovanne
    Nov 21 '18 at 12:58













  • I'm thinking the same, the only problem is there's other stuff to go underneath those icons like directory structure etc.

    – Tony
    Nov 21 '18 at 13:04











  • In this case, you can't use a Navigation Drawer. You must create a Fragment and set yourself the Navigation Drawer behavior (being this a TV app, no need to worry about side scrolling events). Navigation Drawer is used to help the user navigate through the app's screens and was not built to show dynamic info.

    – Giovanne
    Nov 21 '18 at 13:15
















0















enter image description here



The above behaves like an Android Navigation Drawer Menu but written in c++ and I'm trying to replicate it in Android using Navigation Drawer Menu I have achieved it but vertically. This is a part of an app for TV and not for the smart phones. I cannot seem to display the contents in Horizontally is this even possible ? Can someone please help!
This is what I have manged so far;



enter image description here



activity_navigation_drawer.xml



<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
android:id="@+id/nav_drawer">

<ImageView
android:id="@+id/icon"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_marginLeft="1dp"
android:contentDescription="Icons"/>

<TextView
android:id="@+id/titles"
android:layout_width ="90dp"
android:layout_height ="wrap_content"
android:layout_marginLeft ="-40dp"
android:layout_marginTop ="70dp"
android:textColor ="@color/colorPrimary"
android:textSize="16sp"
android:layout_below ="@+id/icon"/>
</LinearLayout>


NavigationAdapter.java



public class NavigationAdapter extends ArrayAdapter<String> {
private final Context context;
private final String titles;
private final int icon;

public NavigationAdapter(Context context, int icon, String titles){
super(context, R.layout.activity_navigation_drawer,titles);
this.context=context;
this.icon = icon;
this.titles = titles;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.activity_navigation_drawer,parent,false);

ImageView imageView=(ImageView)rowView.findViewById(R.id.icon);
TextView textView = (TextView)rowView.findViewById(R.id.titles);

imageView.setImageResource(icon[position]);
textView.setText(titles[position]);

return rowView;
}
}


MainActivity.java



public class MainActivity extends AppCompatActivity {
private ListView mDrawerList1;
private DrawerLayout mDrawerLayout;

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

mDrawerList1 = (ListView) findViewById(R.id.resource_bank);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
addDrawerItems();

navOne = (ImageButton) findViewById(R.id.nav_one);
navOne.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
mDrawerLayout.closeDrawer(GravityCompat.START);
} else {
mDrawerLayout.openDrawer(GravityCompat.START);
}
}
});
}

private void addDrawerItems() {

int icon = {R.drawable.xxx_my_computer,
R.drawable.xxx_my_items,
R.drawable.xxx_favorite,
R.drawable.xxx_remote,
};

String name ={"Computer",
"Items",
"Favorite",
"Remote",
};

NavigationAdapter onAdapter = new NavigationAdapter(MainActivity.this,icon,name);
mDrawerList1.setAdapter(onAdapter);

mDrawerList1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(MainActivity.this, "Resource Bank", Toast.LENGTH_SHORT).show();
}
});
}
}









share|improve this question

























  • set parant LinearLayout android:orientation="vertical"

    – Ali
    Nov 21 '18 at 12:48











  • Thanks but it doesn't work.

    – Tony
    Nov 21 '18 at 12:52











  • Well... I don't think it's possible due the way the Navigator deals with the menu layout. But looking at your example in C++, you can achieve this by setting the buttons in a XML layout and set it to the header of the NavigationView tag.

    – Giovanne
    Nov 21 '18 at 12:58













  • I'm thinking the same, the only problem is there's other stuff to go underneath those icons like directory structure etc.

    – Tony
    Nov 21 '18 at 13:04











  • In this case, you can't use a Navigation Drawer. You must create a Fragment and set yourself the Navigation Drawer behavior (being this a TV app, no need to worry about side scrolling events). Navigation Drawer is used to help the user navigate through the app's screens and was not built to show dynamic info.

    – Giovanne
    Nov 21 '18 at 13:15














0












0








0








enter image description here



The above behaves like an Android Navigation Drawer Menu but written in c++ and I'm trying to replicate it in Android using Navigation Drawer Menu I have achieved it but vertically. This is a part of an app for TV and not for the smart phones. I cannot seem to display the contents in Horizontally is this even possible ? Can someone please help!
This is what I have manged so far;



enter image description here



activity_navigation_drawer.xml



<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
android:id="@+id/nav_drawer">

<ImageView
android:id="@+id/icon"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_marginLeft="1dp"
android:contentDescription="Icons"/>

<TextView
android:id="@+id/titles"
android:layout_width ="90dp"
android:layout_height ="wrap_content"
android:layout_marginLeft ="-40dp"
android:layout_marginTop ="70dp"
android:textColor ="@color/colorPrimary"
android:textSize="16sp"
android:layout_below ="@+id/icon"/>
</LinearLayout>


NavigationAdapter.java



public class NavigationAdapter extends ArrayAdapter<String> {
private final Context context;
private final String titles;
private final int icon;

public NavigationAdapter(Context context, int icon, String titles){
super(context, R.layout.activity_navigation_drawer,titles);
this.context=context;
this.icon = icon;
this.titles = titles;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.activity_navigation_drawer,parent,false);

ImageView imageView=(ImageView)rowView.findViewById(R.id.icon);
TextView textView = (TextView)rowView.findViewById(R.id.titles);

imageView.setImageResource(icon[position]);
textView.setText(titles[position]);

return rowView;
}
}


MainActivity.java



public class MainActivity extends AppCompatActivity {
private ListView mDrawerList1;
private DrawerLayout mDrawerLayout;

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

mDrawerList1 = (ListView) findViewById(R.id.resource_bank);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
addDrawerItems();

navOne = (ImageButton) findViewById(R.id.nav_one);
navOne.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
mDrawerLayout.closeDrawer(GravityCompat.START);
} else {
mDrawerLayout.openDrawer(GravityCompat.START);
}
}
});
}

private void addDrawerItems() {

int icon = {R.drawable.xxx_my_computer,
R.drawable.xxx_my_items,
R.drawable.xxx_favorite,
R.drawable.xxx_remote,
};

String name ={"Computer",
"Items",
"Favorite",
"Remote",
};

NavigationAdapter onAdapter = new NavigationAdapter(MainActivity.this,icon,name);
mDrawerList1.setAdapter(onAdapter);

mDrawerList1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(MainActivity.this, "Resource Bank", Toast.LENGTH_SHORT).show();
}
});
}
}









share|improve this question
















enter image description here



The above behaves like an Android Navigation Drawer Menu but written in c++ and I'm trying to replicate it in Android using Navigation Drawer Menu I have achieved it but vertically. This is a part of an app for TV and not for the smart phones. I cannot seem to display the contents in Horizontally is this even possible ? Can someone please help!
This is what I have manged so far;



enter image description here



activity_navigation_drawer.xml



<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
android:id="@+id/nav_drawer">

<ImageView
android:id="@+id/icon"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_marginLeft="1dp"
android:contentDescription="Icons"/>

<TextView
android:id="@+id/titles"
android:layout_width ="90dp"
android:layout_height ="wrap_content"
android:layout_marginLeft ="-40dp"
android:layout_marginTop ="70dp"
android:textColor ="@color/colorPrimary"
android:textSize="16sp"
android:layout_below ="@+id/icon"/>
</LinearLayout>


NavigationAdapter.java



public class NavigationAdapter extends ArrayAdapter<String> {
private final Context context;
private final String titles;
private final int icon;

public NavigationAdapter(Context context, int icon, String titles){
super(context, R.layout.activity_navigation_drawer,titles);
this.context=context;
this.icon = icon;
this.titles = titles;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.activity_navigation_drawer,parent,false);

ImageView imageView=(ImageView)rowView.findViewById(R.id.icon);
TextView textView = (TextView)rowView.findViewById(R.id.titles);

imageView.setImageResource(icon[position]);
textView.setText(titles[position]);

return rowView;
}
}


MainActivity.java



public class MainActivity extends AppCompatActivity {
private ListView mDrawerList1;
private DrawerLayout mDrawerLayout;

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

mDrawerList1 = (ListView) findViewById(R.id.resource_bank);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
addDrawerItems();

navOne = (ImageButton) findViewById(R.id.nav_one);
navOne.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
mDrawerLayout.closeDrawer(GravityCompat.START);
} else {
mDrawerLayout.openDrawer(GravityCompat.START);
}
}
});
}

private void addDrawerItems() {

int icon = {R.drawable.xxx_my_computer,
R.drawable.xxx_my_items,
R.drawable.xxx_favorite,
R.drawable.xxx_remote,
};

String name ={"Computer",
"Items",
"Favorite",
"Remote",
};

NavigationAdapter onAdapter = new NavigationAdapter(MainActivity.this,icon,name);
mDrawerList1.setAdapter(onAdapter);

mDrawerList1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(MainActivity.this, "Resource Bank", Toast.LENGTH_SHORT).show();
}
});
}
}






android navigation-drawer






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 13:24









Giovanne

784




784










asked Nov 21 '18 at 12:35









TonyTony

139313




139313













  • set parant LinearLayout android:orientation="vertical"

    – Ali
    Nov 21 '18 at 12:48











  • Thanks but it doesn't work.

    – Tony
    Nov 21 '18 at 12:52











  • Well... I don't think it's possible due the way the Navigator deals with the menu layout. But looking at your example in C++, you can achieve this by setting the buttons in a XML layout and set it to the header of the NavigationView tag.

    – Giovanne
    Nov 21 '18 at 12:58













  • I'm thinking the same, the only problem is there's other stuff to go underneath those icons like directory structure etc.

    – Tony
    Nov 21 '18 at 13:04











  • In this case, you can't use a Navigation Drawer. You must create a Fragment and set yourself the Navigation Drawer behavior (being this a TV app, no need to worry about side scrolling events). Navigation Drawer is used to help the user navigate through the app's screens and was not built to show dynamic info.

    – Giovanne
    Nov 21 '18 at 13:15



















  • set parant LinearLayout android:orientation="vertical"

    – Ali
    Nov 21 '18 at 12:48











  • Thanks but it doesn't work.

    – Tony
    Nov 21 '18 at 12:52











  • Well... I don't think it's possible due the way the Navigator deals with the menu layout. But looking at your example in C++, you can achieve this by setting the buttons in a XML layout and set it to the header of the NavigationView tag.

    – Giovanne
    Nov 21 '18 at 12:58













  • I'm thinking the same, the only problem is there's other stuff to go underneath those icons like directory structure etc.

    – Tony
    Nov 21 '18 at 13:04











  • In this case, you can't use a Navigation Drawer. You must create a Fragment and set yourself the Navigation Drawer behavior (being this a TV app, no need to worry about side scrolling events). Navigation Drawer is used to help the user navigate through the app's screens and was not built to show dynamic info.

    – Giovanne
    Nov 21 '18 at 13:15

















set parant LinearLayout android:orientation="vertical"

– Ali
Nov 21 '18 at 12:48





set parant LinearLayout android:orientation="vertical"

– Ali
Nov 21 '18 at 12:48













Thanks but it doesn't work.

– Tony
Nov 21 '18 at 12:52





Thanks but it doesn't work.

– Tony
Nov 21 '18 at 12:52













Well... I don't think it's possible due the way the Navigator deals with the menu layout. But looking at your example in C++, you can achieve this by setting the buttons in a XML layout and set it to the header of the NavigationView tag.

– Giovanne
Nov 21 '18 at 12:58







Well... I don't think it's possible due the way the Navigator deals with the menu layout. But looking at your example in C++, you can achieve this by setting the buttons in a XML layout and set it to the header of the NavigationView tag.

– Giovanne
Nov 21 '18 at 12:58















I'm thinking the same, the only problem is there's other stuff to go underneath those icons like directory structure etc.

– Tony
Nov 21 '18 at 13:04





I'm thinking the same, the only problem is there's other stuff to go underneath those icons like directory structure etc.

– Tony
Nov 21 '18 at 13:04













In this case, you can't use a Navigation Drawer. You must create a Fragment and set yourself the Navigation Drawer behavior (being this a TV app, no need to worry about side scrolling events). Navigation Drawer is used to help the user navigate through the app's screens and was not built to show dynamic info.

– Giovanne
Nov 21 '18 at 13:15





In this case, you can't use a Navigation Drawer. You must create a Fragment and set yourself the Navigation Drawer behavior (being this a TV app, no need to worry about side scrolling events). Navigation Drawer is used to help the user navigate through the app's screens and was not built to show dynamic info.

– Giovanne
Nov 21 '18 at 13:15












1 Answer
1






active

oldest

votes


















1














just use bottomnavigationview and make Relative layout parent layout and then use alignparrenttop=true in bottomnavigation view simple



or



make a linearlayout with horizontal orientation and then gave it weightsum acourding your option like if you want show 3 option thn gave it weightsum 3 and divide it in 3 option simple






share|improve this answer























    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
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53412164%2fhow-to-add-items-to-navigation-drawer-menu-horizontally%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









    1














    just use bottomnavigationview and make Relative layout parent layout and then use alignparrenttop=true in bottomnavigation view simple



    or



    make a linearlayout with horizontal orientation and then gave it weightsum acourding your option like if you want show 3 option thn gave it weightsum 3 and divide it in 3 option simple






    share|improve this answer




























      1














      just use bottomnavigationview and make Relative layout parent layout and then use alignparrenttop=true in bottomnavigation view simple



      or



      make a linearlayout with horizontal orientation and then gave it weightsum acourding your option like if you want show 3 option thn gave it weightsum 3 and divide it in 3 option simple






      share|improve this answer


























        1












        1








        1







        just use bottomnavigationview and make Relative layout parent layout and then use alignparrenttop=true in bottomnavigation view simple



        or



        make a linearlayout with horizontal orientation and then gave it weightsum acourding your option like if you want show 3 option thn gave it weightsum 3 and divide it in 3 option simple






        share|improve this answer













        just use bottomnavigationview and make Relative layout parent layout and then use alignparrenttop=true in bottomnavigation view simple



        or



        make a linearlayout with horizontal orientation and then gave it weightsum acourding your option like if you want show 3 option thn gave it weightsum 3 and divide it in 3 option simple







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 21 '18 at 12:48









        Mukesh RawatMukesh Rawat

        212




        212
































            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53412164%2fhow-to-add-items-to-navigation-drawer-menu-horizontally%23new-answer', 'question_page');
            }
            );

            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







            Popular posts from this blog

            How to pass form data using jquery Ajax to insert data in database?

            National Museum of Racing and Hall of Fame

            Guess what letter conforming each word