如何同时在导航条选框的列表视图中制作所有textView?

时间:2015-01-09 09:37:53

标签: android listview android-listview textview marquee

在我的应用中,我有一个Navigation DrawerListView ImageView NavigatinDrawer' has an TextView , TextView and another tv_navDrawerOptionDescription`的with id已显示下面。

导航抽屉的ListView中的项目数是三个项目(eco-assist,data-logger-exit),每个项目都有ImageView,TextView“作为标题”,另一个TextView“作为描述”

我想要做的是,当抽屉被打开时,NavigationDrawer ListView中我所拥有的三个项目的所有“描述TextView”应该永远水平旋转为marquee

当我运行应用程序时。我发现描述textview是静态的而不是旋转的

我的尝试发布了 navigationDrawer列表视图的布局

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

1 个答案:

答案 0 :(得分:2)

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