在ListView中实现Horizo​​ntalScrollView

时间:2015-02-28 15:50:55

标签: android listview horizontalscrollview

我使用此示例codethis实现了成功的Horizo​​ntalScrollView。这将从服务器获取数据

但现在我正在尝试在ListView中创建一个水平滚动视图,我找不到正确的方法!所以列表的每个元素都包含这个:

> RelativeLayout(vertical)
  > RelativeLayout
    > ImageView
    > TextView
  > HorizontalScrollView 
    > LinearLayout (horizontal)

MainActivity

        actorsList = new ArrayList<Actors>();

        new JSONAsyncTask().execute("http://microblogging.wingnity.com/JSONParsingTutorial/jsonActors");    

centerLockHorizontalScrollview = (CenterLockHorizontalScrollview) findViewById(R.id.scrollView);        
            adapter = new ActorAdapter(getApplicationContext(), R.layout.row, actorsList);      
            centerLockHorizontalScrollview.setAdapter(MainActivity.this, adapter); 

listview.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"    android:background="#F1F1F1"
    >

    <ListView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

    </ListView>

</LinearLayout> 

适配器类中的getView方法的代码

@Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        View v = convertView;
        if (v == null) {
            holder = new ViewHolder();
            v = vi.inflate(Resource, null);
            holder.imageview = (ImageView) v.findViewById(R.id.ivImage);
            holder.tvName = (TextView) v.findViewById(R.id.tvName);
             //     //    //     //    //     ///
        } else {
            holder = (ViewHolder) v.getTag();
        }
        holder.imageview.setImageResource(R.drawable.ic_launcher);
        new DownloadImageTask(holder.imageview).execute(actorList.get(position).getImage());
        holder.tvName.setText(actorList.get(position).getName());

       //     //     //     //    //     ///

        v.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                Log.i("mh", ""+actorList.get(position).getName());

            }
        });
        return v;

    }

    static class ViewHolder {
        public ImageView imageview;
        public TextView tvName;
          //     //       //

    }

0 个答案:

没有答案