我该怎么做?
解决方法 你可以像我所做的那样在浏览视图中使用ListvIEw.这样做的好处是可以更好地控制这一点:<androID.support.design.Widget.NavigationVIEw androID:ID="@+ID/nav_vIEw" androID:layout_wIDth="wrap_content" androID:layout_height="match_parent" androID:layout_gravity="start" androID:fitsSystemwindows="true" app:headerLayout="@layout/header" > <ListVIEw androID:ID="@+ID/navigationmenu" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:layout_margintop="192dp" androID:background="@androID:color/white"> </ListVIEw></androID.support.design.Widget.NavigationVIEw>
nav项目应该是这样的:
<?xml version="1.0" enCoding="utf-8"?><relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:orIEntation="horizontal" androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:background="@color/cardvIEw_dark_background" > <ImageVIEw androID:ID="@+ID/img" androID:layout_wIDth="wrap_content" androID:layout_alignParentRight="true" androID:layout_height="wrap_content" androID:src="@drawable/vIEwList" /> <TextVIEw androID:ID="@+ID/tvlstname" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:textSize="20dp" androID:layout_marginRight="30dp" androID:textcolor="@color/colorPrimary" /></relativeLayout>
和navcustomadapter这样:
package com.example.androID.dezcook;import androID.content.Context;import androID.vIEw.LayoutInflater;import androID.vIEw.VIEw;import androID.vIEw.VIEwGroup;import androID.Widget.BaseAdapter;import androID.Widget.ImageVIEw;import androID.Widget.TextVIEw;import androID.Widget.Toast;/** * Created by AndroID on 6/4/2016. */public class navCustomAdapter extends BaseAdapter { String[] result; Context context; int[] imageID; private static LayoutInflater inflater=null; public navCustomAdapter(MainActivity mainActivity,String[] prgmnameList,int[] prgImages) { result=prgmnameList; imageID=prgImages; context =mainActivity; inflater =(LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE); } @OverrIDe public int getCount() { return result.length; } @OverrIDe public Object getItem(int position) { return position; } @OverrIDe public long getItemID(int position) { return position; } public class Holder { TextVIEw tv; ImageVIEw img; } @OverrIDe public VIEw getVIEw(final int position,VIEw convertVIEw,VIEwGroup parent) { Holder holder=new Holder(); VIEw rowVIEw; rowVIEw=inflater.inflate(R.layout.navitem,null); holder.tv=(TextVIEw)rowVIEw.findVIEwByID(R.ID.tvlstname); holder.img=(ImageVIEw)rowVIEw.findVIEwByID(R.ID.img); holder.tv.setText(result[position]); holder.img.setimageResource(imageID[position]); rowVIEw.setonClickListener(new VIEw.OnClickListener() { @OverrIDe public voID onClick(VIEw v) { Toast.makeText(context,"you Clicked "+result[position],Toast.LENGTH_LONG).show(); } } ); return rowVIEw; }}
最终在主要活动中称之为:
ListVIEw lv=(ListVIEw)findVIEwByID(R.ID.navigationmenu); lv.setAdapter(new navCustomAdapter(this,navItem,prgmImages)总结
以上是内存溢出为你收集整理的android – 如何更改NavigationView中菜单项的图标方向?全部内容,希望文章能够帮你解决android – 如何更改NavigationView中菜单项的图标方向?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)