如何同时使导航抽屉选框列表视图中的所有文本视图?
how to make all the textView in a listview of a navigationdrawer marquee simultaneously?
在我的应用程序中,我有一个 Navigation Drawer
、NavigatinDrawer' has an
ImageView,
TextViewand another
TextViewwith id
[= 的 ListView
42=]`如下图。
导航抽屉的ListView中的项目数是三个项目(eco-assist、data-logger-exit),每个项目都有ImageView、TextView"as title"和另一个TextView“作为描述”。 =22=]
我想做的是,当抽屉打开时,我在 NavigationDrawer
ListView
中的三个项目中的所有 "description TextView" 应该永远水平旋转,因为 marquee
.
当我 运行 应用程序时。我发现描述 textview
是静止的而不是旋转的
我的尝试已发布在下方
导航抽屉列表视图的布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/list_selector">
<ImageView
android:id="@+id/iv_navDrawerOptionImage"
android:layout_width="25dp"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:contentDescription="@string/desc_list_item_icon"
android:layout_centerVertical="true"/>
<TextView
android:id="@+id/tv_navDrawerOptionTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="@id/iv_navDrawerOptionImage"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:textColor="@color/list_item_title"
android:gravity="center_vertical"/>
<TextView
android:id="@+id/tv_navDrawerOptionDescription"
android:layout_below="@id/tv_navDrawerOptionTitle"
android:singleLine="true"
android:lines="1"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
NavigationDrawer ListAdapter:
public class NavDrawerListAdapter extends BaseAdapter{
private Context context;
private ArrayList<NavDrawerModell> navDrawerModel;
public NavDrawerListAdapter(Context context, ArrayList<NavDrawerModell> navDrawerModell) {
// TODO Auto-generated constructor stub
this.context = context;
this.navDrawerModel = navDrawerModell;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return this.navDrawerModel.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return this.navDrawerModel.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
if (convertView == null) {
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
convertView = layoutInflater.inflate(R.layout.drawer_list_layout, null);
}
ImageView iv_Icon = (ImageView) convertView.findViewById(R.id.iv_navDrawerOptionImage);
TextView tv_Title = (TextView) convertView.findViewById(R.id.tv_navDrawerOptionTitle);
TextView tv_Desc = (TextView) convertView.findViewById(R.id.tv_navDrawerOptionDescription);
iv_Icon.setImageResource(navDrawerModel.get(position).getIcon());
tv_Title.setText(navDrawerModel.get(position).gettitle());
tv_Desc.setText(navDrawerModel.get(position).getDescription());
return convertView;
}
}
<TextView
android:id="@+id/tv_navDrawerOptionDescription"
android:layout_below="@id/tv_navDrawerOptionTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true">
请尝试上面的代码,看看是否可行。
编辑:
在子类BaseAdapter的getView函数中添加如下代码:
tv_Desc.setText(navDrawerModel.get(position).getDescription());
tv_Desc.setSelected(true);
tv_Desc.requestFocus();
在我的应用程序中,我有一个 Navigation Drawer
、NavigatinDrawer' has an
ImageView,
TextViewand another
TextViewwith id
[= 的 ListView
42=]`如下图。
导航抽屉的ListView中的项目数是三个项目(eco-assist、data-logger-exit),每个项目都有ImageView、TextView"as title"和另一个TextView“作为描述”。 =22=]
我想做的是,当抽屉打开时,我在 NavigationDrawer
ListView
中的三个项目中的所有 "description TextView" 应该永远水平旋转,因为 marquee
.
当我 运行 应用程序时。我发现描述 textview
是静止的而不是旋转的
我的尝试已发布在下方 导航抽屉列表视图的布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/list_selector">
<ImageView
android:id="@+id/iv_navDrawerOptionImage"
android:layout_width="25dp"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:contentDescription="@string/desc_list_item_icon"
android:layout_centerVertical="true"/>
<TextView
android:id="@+id/tv_navDrawerOptionTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="@id/iv_navDrawerOptionImage"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:textColor="@color/list_item_title"
android:gravity="center_vertical"/>
<TextView
android:id="@+id/tv_navDrawerOptionDescription"
android:layout_below="@id/tv_navDrawerOptionTitle"
android:singleLine="true"
android:lines="1"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
NavigationDrawer ListAdapter:
public class NavDrawerListAdapter extends BaseAdapter{
private Context context;
private ArrayList<NavDrawerModell> navDrawerModel;
public NavDrawerListAdapter(Context context, ArrayList<NavDrawerModell> navDrawerModell) {
// TODO Auto-generated constructor stub
this.context = context;
this.navDrawerModel = navDrawerModell;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return this.navDrawerModel.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return this.navDrawerModel.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
if (convertView == null) {
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
convertView = layoutInflater.inflate(R.layout.drawer_list_layout, null);
}
ImageView iv_Icon = (ImageView) convertView.findViewById(R.id.iv_navDrawerOptionImage);
TextView tv_Title = (TextView) convertView.findViewById(R.id.tv_navDrawerOptionTitle);
TextView tv_Desc = (TextView) convertView.findViewById(R.id.tv_navDrawerOptionDescription);
iv_Icon.setImageResource(navDrawerModel.get(position).getIcon());
tv_Title.setText(navDrawerModel.get(position).gettitle());
tv_Desc.setText(navDrawerModel.get(position).getDescription());
return convertView;
}
}
<TextView
android:id="@+id/tv_navDrawerOptionDescription"
android:layout_below="@id/tv_navDrawerOptionTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true">
请尝试上面的代码,看看是否可行。
编辑:
在子类BaseAdapter的getView函数中添加如下代码:
tv_Desc.setText(navDrawerModel.get(position).getDescription());
tv_Desc.setSelected(true);
tv_Desc.requestFocus();