Salut je travaille avec Android. J'ai ajouté le tiroir de navigation Android comme dans le courrier électronique à mon application avec succès. À présent, je souhaite ajouter une vue d'image de profil comme dans l'image. Je l'ai essayé dans l'élément de la liste. mais je veux plus d'espace comme dans l'image..Comment puis-je le faire ??? S'il vous plaît aidez-moi, je suis nouveau sur Android
voici mon code pour l'élément de liste
mTitle = mDrawerTitle = getTitle();
// load slide menu items
navMenuTitles = getResources().getStringArray(R.array.nav_drawer_items);
// nav drawer icons from resources
navMenuIcons = getResources()
.obtainTypedArray(R.array.nav_drawer_icons);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.list_slidermenu);
navDrawerItems = new ArrayList<NavDrawerItem>();
// adding nav drawer items to array
// Home
navDrawerItems.add(new NavDrawerItem(navMenuTitles[0], navMenuIcons.getResourceId(0, -1)));
navDrawerItems.add(new NavDrawerItem(navMenuTitles[1], navMenuIcons.getResourceId(1, -1)));
// Find People
navDrawerItems.add(new NavDrawerItem(navMenuTitles[2], navMenuIcons.getResourceId(2, -1)));
// Photos
navDrawerItems.add(new NavDrawerItem(navMenuTitles[3], navMenuIcons.getResourceId(3, -1)));
// Communities, Will add a counter here
navDrawerItems.add(new NavDrawerItem(navMenuTitles[4], navMenuIcons.getResourceId(4, -1), true, "22"));
// Pages
navDrawerItems.add(new NavDrawerItem(navMenuTitles[5], navMenuIcons.getResourceId(5, -1)));
// What's hot, We will add a counter here
navDrawerItems.add(new NavDrawerItem(navMenuTitles[6], navMenuIcons.getResourceId(6, -1), true, "50+"));
// Recycle the typed array
navMenuIcons.recycle();
mDrawerList.setOnItemClickListener(new SlideMenuClickListener());
// setting the nav drawer list adapter
adapter = new NavDrawerListAdapter(getApplicationContext(),
navDrawerItems);
mDrawerList.setAdapter(adapter);
Je résous également ce problème. Il suffit de modifier une partie du code en XML et Java.
Changer le code suivre le code ci-dessous ...... Je pense résoudre votre problème
<Android.support.v4.widget.DrawerLayout xmlns:Android="http://schemas.Android.com/apk/res/Android"
Android:id="@+id/drawer_layout"
Android:layout_width="match_parent"
Android:layout_height="match_parent"
Android:background="#ffffff" >
<!-- Framelayout to display Fragments -->
<FrameLayout
Android:id="@+id/frame_container"
Android:layout_width="match_parent"
Android:layout_height="match_parent" />
<!-- Listview to display slider menu -->
<LinearLayout
Android:id="@+id/drawerll"
Android:layout_width="240dp"
Android:layout_height="match_parent"
Android:layout_gravity="start"
Android:orientation="vertical" >
<LinearLayout
Android:id="@+id/drawer"
Android:layout_width="240dp"
Android:layout_height="wrap_content"
Android:layout_gravity="start"
Android:background="@color/list_item_title"
Android:gravity="center_vertical"
Android:orientation="horizontal" >
<ImageView
Android:layout_width="80dp"
Android:layout_height="80dp"
Android:paddingLeft="20dp"
Android:src="@drawable/pic_pic" />
<LinearLayout
Android:id="@+id/drawer"
Android:layout_width="wrap_content"
Android:layout_height="wrap_content"
Android:layout_marginLeft="10dp"
Android:background="@color/list_item_title"
Android:orientation="vertical" >
<TextView
Android:layout_width="wrap_content"
Android:layout_height="wrap_content"
Android:gravity="center"
Android:text="Shohel Rana"
Android:textSize="14sp" />
<TextView
Android:layout_width="wrap_content"
Android:layout_height="wrap_content"
Android:layout_marginTop="5dp"
Android:gravity="center"
Android:text="[email protected]"
Android:textSize="14sp" />
</LinearLayout>
</LinearLayout>
<ListView
Android:id="@+id/list_slidermenu"
Android:layout_width="match_parent"
Android:layout_height="match_parent"
Android:background="@color/list_item_title"
Android:choiceMode="singleChoice"
Android:dividerHeight="1dp"
Android:listSelector="@drawable/list_selector" />
</LinearLayout>
</Android.support.v4.widget.DrawerLayout>
Et le code Java vient d'être ajouté ci-dessous code ::::
tiroir final booléenOpen = mDrawerLayout.isDrawerOpen (tiroirll);
tirette signifie ici disposition linéaire totale. et mDrawerLayout.closeDrawer (tiroirll);
et fermer la disposition des tiroirs ....
Voici le code Java total:
package by.fitbody;`enter code here`
import Java.util.ArrayList;
import Android.app.ActionBar;
import Android.app.Activity;
import Android.app.Fragment;
import Android.app.FragmentManager;
import Android.app.SearchManager;
import Android.content.Context;
import Android.content.Intent;
import Android.content.res.Configuration;
import Android.graphics.drawable.ColorDrawable;
import Android.os.Bundle;
import Android.support.v4.app.ActionBarDrawerToggle;
import Android.support.v4.widget.DrawerLayout;
import Android.util.Log;
import Android.view.Menu;
import Android.view.MenuInflater;
import Android.view.MenuItem;
import Android.view.View;
import Android.widget.AdapterView;
import Android.widget.LinearLayout;
import Android.widget.ListView;
import Android.widget.SearchView;
import Android.widget.Toast;
import by.fitbody.adapter.NavDrawerListAdapter;
import by.fitbody.model.NavDrawerItem;
public class MainActivity extends Activity {
private DrawerLayout mDrawerLayout;
private ListView mDrawerList;
private ActionBarDrawerToggle mDrawerToggle;
// nav drawer title
private CharSequence mDrawerTitle;
// used to store app title
private CharSequence mTitle;
// slide menu items
private String[] navMenuTitles;
// private TypedArray navMenuIcons;
private ArrayList<NavDrawerItem> navDrawerItems;
private NavDrawerListAdapter adapter;
private Context con = null;
LinearLayout drawerll;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
con = this;
final ActionBar bar = getActionBar();
bar.setBackgroundDrawable(new ColorDrawable(getResources().getColor(
R.color.customRed)));
bar.setIcon(R.drawable.articles_05);
mTitle = mDrawerTitle = getTitle();
// load slide menu items
navMenuTitles = getResources().getStringArray(R.array.nav_drawer_items);
// nav drawer icons from resources
// navMenuIcons = getResources()
// .obtainTypedArray(R.array.nav_drawer_icons);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.list_slidermenu);
drawerll = (LinearLayout) findViewById(R.id.drawerll);
makeSlideList();
// enabling action bar app icon and behaving it as toggle button
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
R.drawable.main_menu, // nav menu toggle icon
R.string.app_name, // nav drawer open - description for
// accessibility
R.string.app_name // nav drawer close - description for
// accessibility
) {
@Override
public void onDrawerClosed(View view) {
getActionBar().setTitle(mTitle);
// calling onPrepareOptionsMenu() to show action bar icons
invalidateOptionsMenu();
}
@Override
public void onDrawerOpened(View drawerView) {
getActionBar().setTitle(mDrawerTitle);
// calling onPrepareOptionsMenu() to hide action bar icons
invalidateOptionsMenu();
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
if (savedInstanceState == null) {
// on first time display view for first nav item
displayView(0);
}
}
/*
* make slide list
*/`enter code here`
private void makeSlideList() {
// TODO Auto-generated method stub
navDrawerItems = new ArrayList<NavDrawerItem>();
// adding nav drawer items to array
// Home
navDrawerItems.add(new NavDrawerItem(navMenuTitles[0]));
// Find People
navDrawerItems.add(new NavDrawerItem(navMenuTitles[1]));
// Photos
navDrawerItems.add(new NavDrawerItem(navMenuTitles[2]));
// Communities, Will add a counter here
navDrawerItems.add(new NavDrawerItem(navMenuTitles[3]));
// Pages
navDrawerItems.add(new NavDrawerItem(navMenuTitles[4]));
// What's hot, We will add a counter here
navDrawerItems.add(new NavDrawerItem(navMenuTitles[5]));
navDrawerItems.add(new NavDrawerItem(navMenuTitles[6]));
navDrawerItems.add(new NavDrawerItem(navMenuTitles[7]));
navDrawerItems.add(new NavDrawerItem(navMenuTitles[8]));
// Recycle the typed array
// navMenuIcons.recycle();
mDrawerList.setOnItemClickListener(new SlideMenuClickListener());
// setting the nav drawer list adapter
adapter = new NavDrawerListAdapter(getApplicationContext(),
navDrawerItems);
mDrawerList.setAdapter(adapter);
}
/**
* Slide menu item click listener
* */
private class SlideMenuClickListener implements
ListView.OnItemClickListener {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
// display view for selected nav drawer item
displayView(position);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
final MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.actionbarmenu, menu);
// Associate searchable configuration with the SearchView
final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
final SearchView searchView = (SearchView) menu.findItem(
R.id.action_search).getActionView();
searchView.setSearchableInfo(searchManager
.getSearchableInfo(getComponentName()));
return super.onCreateOptionsMenu(menu);
}
/*
* fo(non-Javadoc)
*
* @see Android.app.Activity#onNewIntent(Android.content.Intent)
*
*
* for search bar
*/
@Override
protected void onNewIntent(Intent intent) {
setIntent(intent);
handleIntent(intent);
}
/**
* Handling intent data
*/
private void handleIntent(Intent intent) {
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
final String query = intent.getStringExtra(SearchManager.QUERY);
Log.e("Search text is ", query + "");
/**
* Use this query to display search results like 1. Getting the data
* from SQLite and showing in listview 2. Making webrequest and
* displaying the data For now we just display the query only
*/
Toast.makeText(con, "Query is " + query, 1000).show();
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// toggle nav drawer on selecting action bar app icon/title
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
// Handle action bar actions click
switch (item.getItemId()) {
case R.id.action_rate:
Toast.makeText(con, "rate button is clicked", 1000).show();
return true;
case R.id.action_best:
Toast.makeText(con, "Best button is clicked", 1000).show();
return true;
case R.id.action_liked:
Toast.makeText(con, "liked button is clicked", 1000).show();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
/* *
* Called when invalidateOptionsMenu() is triggered
*/
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
// if nav drawer is opened, hide the action items
/*
* active those code if you want to hide options menu when drawer is
* opened.
*/
final boolean drawerOpen = mDrawerLayout.isDrawerOpen(drawerll);
menu.findItem(R.id.action_best).setVisible(!drawerOpen);
menu.findItem(R.id.action_liked).setVisible(!drawerOpen);
menu.findItem(R.id.action_rate).setVisible(!drawerOpen);
return super.onPrepareOptionsMenu(menu);
}
/**
* Diplaying fragment view for selected nav drawer list item
* */
private void displayView(int position) {
// update the main content by replacing fragments
Fragment fragment = null;
switch (position) {
case 0:
fragment = new ArticleFragment(position);
break;
case 1:
fragment = new ArticleFragment(position);
break;
case 2:
fragment = new ArticleFragment(position);
break;
case 3:
fragment = new ArticleFragment(position);
break;
case 4:
fragment = new ForumFragment();
break;
case 5:
final Intent i = new Intent(con, FitnessClubActivity.class);
startActivity(i);
break;
case 6:
fragment = new ArticleFragment(position);
break;
case 7:
fragment = new ArticleFragment(position);
break;
case 8:
fragment = new AboutUsFragment();
break;
default:
break;
}
if (fragment != null) {
final FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.frame_container, fragment).commit();
// update selected item and title, then close the drawer
mDrawerList.setItemChecked(position, true);
mDrawerList.setSelection(position);
setTitle(navMenuTitles[position]);
mDrawerLayout.closeDrawer(drawerll);
} else {
// error in creating fragment
Log.e("MainActivity", "Error in creating fragment");
}
}
@Override
public void setTitle(CharSequence title) {
mTitle = title;
getActionBar().setTitle(mTitle);
}
/**
* When using the ActionBarDrawerToggle, you must call it during
* onPostCreate() and onConfigurationChanged()...
*/
@Override
protected void onPostCreate(Bundle savedInstanceState) {enter code here`
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
mDrawerToggle.syncState();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Pass any configuration change to the drawer toggls
mDrawerToggle.onConfigurationChanged(newConfig);
}
}
Je pense que cela résoudrait votre problème:
Je viens de modifier le code de ce site: http://www.androidhive.info/2013/11/Android-sliding-menu-using-navigation-drawer/
Vous pouvez également utiliser une vue personnalisée dans NAvigatindrawer non seulement une liste. Créez donc un LinearLayout avec votre image et une listview pour obtenir le résultat.
Regardez ceci SO Thread: Est-il possible d'utiliser autre chose qu'une listview comme tiroir coulissant dans tiroirlayout
S'amuser ;)
Juste pour votre information, vous pouvez utiliser FB parse qui vous donne un moyen très simple d'ajouter ces apis et de récupérer facilement les détails. Ils disposent d'une documentation simple étape par étape.
Vous pouvez lire à ce sujet ici: https://www.parse.com/docs
J'ai résolu cela en utilisant
mDrawerList.addHeaderView();
où vous devez ajouter un objet View