代码之家  ›  专栏  ›  技术社区  ›  Praveen

Android中的水平列表视图?

  •  205
  • Praveen  · 技术社区  · 16 年前

    有没有可能 ListView 水平地?我已经使用图库视图完成了此操作,但所选项目会自动显示在屏幕中央。我不希望所选项目与我单击的位置相同。我怎样才能纠正这个问题?我的想法是 列表视图 水平滚动。分享你的想法?

    19 回复  |  直到 16 年前
        1
  •  110
  •   H. Pauwelyn    9 年前

    根据Android文档 RecyclerView 是在ListView中组织项目并水平显示的新方法吗?

    优势:

    1. 因为通过使用RecyclerView适配器, ViewHolder pattern 是 自动实现
    2. 动画很容易执行
    3. 更多功能

    有关的详细信息 回收视图 :

    1. grokkingandroid.com
    2. antonioleiva.com

    Sample:

    survivingwithandroid.com

    只需添加下面的块 ListView 从垂直到水平

    代码片段

    LinearLayoutManager layoutManager= new LinearLayoutManager(this,LinearLayoutManager.HORIZONTAL, false);
    mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
    mRecyclerView.setLayoutManager(layoutManager);
    
        2
  •  60
  •   Malachiasz Hieu Rocker    13 年前

    保罗不费心去修复他图书馆的错误或者接受用户的修复。这就是为什么我建议使用另一个功能类似的库:

    https://github.com/sephiroth74/HorizontalVariableListView

    更新 :2013年7月24日,作者(sephiroth74)发布了基于android 4.2.2 listview代码的完全重写版本。我必须说,它没有所有的错误,以前的版本有和工作得很好!

        3
  •  28
  •   Xavi Gil    14 年前

    @保罗回答链接到一个伟大的解决方案,但代码不允许使用 Onclicklisteners公司 在items子级上(从不调用回调函数)。我一直在努力寻找解决方案,我决定在这里发布您需要在代码中修改的内容(以防有人需要它)。

    而不是重写 dispatchTouchEvent 重写 onTouchEvent . 使用相同的代码 发送通知 删除方法(你可以在这里读到两者的区别 http://developer.android.com/guide/topics/ui/ui-events.html#EventHandlers )

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        boolean handled = mGesture.onTouchEvent(event);
        return handled;
    }
    

    然后,添加以下代码,决定从项目子项中窃取事件,并将其提供给 偶然事件 或者让他们来处理。

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        switch( ev.getActionMasked() ){
            case MotionEvent.ACTION_DOWN:
                 mInitialX = ev.getX();
                 mInitialY = ev.getY();             
                 return false;
            case MotionEvent.ACTION_MOVE:
                 float deltaX = Math.abs(ev.getX() - mInitialX);
                 float deltaY = Math.abs(ev.getY() - mInitialY);
                 return ( deltaX > 5 || deltaY > 5 );
            default:
                 return super.onInterceptTouchEvent(ev);
        }
    }
    

    最后,不要忘记声明类中的变量:

    private float mInitialX;
    private float mInitialY;
    
        4
  •  23
  •   klimat    10 年前

    由于Google推出了Android支持库V721.0.0,您可以使用RecyclerView水平滚动项目。RecyclerView小部件是一个更高级和更灵活的ListView版本。

    要使用RecyclerView,只需添加依赖项:

    com.android.support:recyclerview-v7:23.0.1
    

    这是一个示例:

    public class MyActivity extends Activity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.my_activity);
    
            RecyclerView recyclerView = (RecyclerView) findViewById(R.id.my_recycler_view);
    
            LinearLayoutManager layoutManager = new LinearLayoutManager(this);
            layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
            recyclerView.setLayoutManager(layoutManager);
    
            MyAdapter adapter = new MyAdapter(myDataset);
            recyclerView.setAdapter(adapter);
        }
    }
    

    有关RecyclerView的详细信息:

        5
  •  21
  •   KimKha Dimitar Dimitrov    10 年前

    这有点(非常)晚了,但我会把这个贴出来,以防有人晚些时候来。

    从android l preview开始的支持库有一个 RecyclerView 这正是你想要的。

    现在,您只能通过l preview sdk获得它,您需要设置 minSdk L . 但是你可以把所有必要的文件复制到你的项目中,然后用那种方式使用它们,直到我正式退出。

    您可以下载预览文档 here .

    警告:回收程序视图的API可能会更改,并且可能有错误。

    更新的

    水平ListView的源代码是:

    LinearLayoutManager layoutManager
        = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
    
    RecyclerView myList = findViewById(R.id.my_recycler_view);
    myList.setLayoutManager(layoutManager);
    
        6
  •  17
  •   Siddhpura Amit    11 年前

    从下载JAR文件 here

    现在将其放入libs文件夹,右键单击并选择“添加为库”

    现在,在main.xml中输入此代码

     <com.devsmart.android.ui.HorizontalListView
        android:id="@+id/hlistview"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        />
    

    现在在Activity类中,如果希望水平列表视图带有图像,则将此代码

      HorizontalListView hListView = (HorizontalListView) findViewById(R.id.hlistview);
        hListView.setAdapter(new HAdapter(this));
    
    
     private class HAdapter extends BaseAdapter {
    
        LayoutInflater inflater;
    
        public HAdapter(Context context) {
            inflater = LayoutInflater.from(context);
    
        }
    
        @Override
        public int getCount() {
            // TODO Auto-generated method stub
            return Const.template.length;
        }
    
        @Override
        public Object getItem(int position) {
            // TODO Auto-generated method stub
            return position;
        }
    
        @Override
        public long getItemId(int position) {
            // TODO Auto-generated method stub
            return position;
        }
    
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            HViewHolder holder;
            if (convertView == null) {
                convertView = inflater.inflate(R.layout.listinflate, null);
                holder = new HViewHolder();
                convertView.setTag(holder);
    
            } else {
                holder = (HViewHolder) convertView.getTag();
            }
            holder.img = (ImageView) convertView.findViewById(R.id.image);
            holder.img.setImageResource(Const.template[position]);
            return convertView;
        }
    
    }
    
    class HViewHolder {
        ImageView img;
    }
    
        7
  •  12
  •   Dmitry Ryadnenko kalyan pvs    10 年前

    其实很简单 : 只需旋转列表视图使其位于其一侧

    mlistView.setRotation(-90);

    然后在给孩子们充气时,应该在getview方法中。你转动孩子站直:

     mylistViewchild.setRotation(90);
    

    编辑: 如果您的ListView在旋转后不适合,请将ListView放置在 RotateLayout 这样地:

     <com.github.rongi.rotate_layout.layout.RotateLayout
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:angle="90"> <!-- Specify rotate angle here -->
    
        <ListView
           android:layout_width="match_parent"
           android:layout_height="match_parent">
        </ListView>
    </com.github.rongi.rotate_layout.layout.RotateLayout>
    
        8
  •  9
  •   fraggjkee    12 年前

    我的解决方案是简单地使用 viewpager widget。它不是中心锁定为 gallery 并且具有用于回收视图的内置功能(as listview )。每当你处理水平滚动列表时,你可能会在Google Play应用程序中看到类似的方法。

    您只需要扩展 pageradapter 并在那里执行一些调整:

    公共类mypageradapter extends pageradapter{ 私有上下文mcontext; 公共MyPageRadapter(上下文上下文){ this.mcontext=上下文; } //根据文档,可以直接使用视图作为关键对象 //如果它们不太复杂 @重写 公共对象实例化项(viewgroup容器,int位置){ LayoutFiller充气器=LayoutFiller.From(mcontext); 视图=充气器。充气(r.layout.item,空); container.addview(视图); 返回视图; } @重写 public void destroyitem(viewgroup容器,int位置,对象对象对象){ container.removeview((view)对象); } @重写 public int getcount()。{ 返回10; } @重写 公共布尔IsViewFromObject(视图视图、对象对象对象){ 返回视图==对象; } //重要提示:页面默认采用所有可用宽度, //因此,让我们重写此方法,以便在单个屏幕中容纳5页 @重写 公共float getpagewidth(int位置){ 返回0.2F; } } < /代码>

    因此,您将拥有带有适配器的水平可滚动小部件,如下所示:

    锁定为 Gallery 并具有可回收视图的内置功能(如 ListView )每当你处理水平滚动的列表时,你可能会在Google Play应用程序中看到类似的方法。

    你只需要延长 PagerAdapter 在那里进行一些调整:

    public class MyPagerAdapter extends PagerAdapter {
    
        private Context mContext;
    
        public MyPagerAdapter(Context context) {
            this.mContext = context;
        }
    
        // As per docs, you may use views as key objects directly 
        // if they aren't too complex
        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            LayoutInflater inflater = LayoutInflater.from(mContext);
            View view = inflater.inflate(R.layout.item, null);
            container.addView(view);
            return view;
        }
    
        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView((View) object);
        }
    
        @Override
        public int getCount() {
            return 10;
        }
    
        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }
    
        // Important: page takes all available width by default,
        // so let's override this method to fit 5 pages within single screen
        @Override
        public float getPageWidth(int position) {
            return 0.2f;
        }
    }
    

    因此,您将拥有带有适配器的水平可滚动小部件,如下所示: enter image description here

        9
  •  7
  •   Community Mohan Dere    9 年前

    我已经开发了一种逻辑,不使用任何外部的水平滚动视图库来实现它,这里是我实现的水平视图,我已经在这里发布了我的答案: https://stackoverflow.com/a/33301582/5479863

    我的JSON回复是:

    ;“searchinfo”:;“stat状态”:“1”,“messa“““““:”su成功”,“clist”:[“id”:“1de57434-795e-49ac-0ca3-5614daecbd4”,“name”:“剧院”,“图像\u URL“:”http://52.25.198.71/miisecretory/cate_image/mo电影.pn“125,,”,”,”id“““““,”,”id“““:”62fe1C92-2192-2-22ebb-7E92-5614-5614dacaad69b,”,”,”,”,”,”,”,”,”clist““““““““““““““.71/miisecretory/category_images/cng.png“,”id“:”8060094c-df4f-5290-7983-5614dad31677,“name”:“酒铺”,“image_url”:“http://52.25.198.71/miisecretory/cate类_image/beer.png”,“id”:“888a90c4-a6b0-c2e2-6b3c-561788e973f6”,“name”:“化学家”,“image u url”:“http://52.25.198.71/miisecretory/cate类image/chemist.png”,“id”:“A39b44ec1-943f-943f-B800-B800-B800-B800-B800-B800-B800-B800/b800-A671-561789A57871,“name”:“food”,“image_url”:“http://52.25.198.71/miisecretory/categor _images/food.png“,”id“:”c44cc53-2fce-8cbe-0715-5614da9c765f,“”name““:”学院“,”image _url“”:”http://52.25.198.71/miisecretory/categor _images/col.png“,”id“:”c71e8757-072b-1bf4-5b25-5614d980ef15,“”name““:”医院“,”image _url“:”http://52.25.198.198.71/miisecretory/categor/categor/categor/categor/miisecretu images/hospital.png“,”id“:”db835491-d1d2-5467-a1A1-5614D9963C94,“name”:“petrol pumps”,“image_url”:“http://52.25.198.71/miisecretory/category_images/petrol.png”,“id”:“f13100ca-4052-c0f4-863a-5614d9631afb”,“name”:“atm”,“image_url”:“http://52.25.198.71/miisecretory/category_images/atm.png”]
    < /代码> 
    
    

    布局文件:

    <?xml version=“1.0”encoding=“utf-8”?gt;
    <linearlayout xmlns:android=“http://schemas.android.com/apk/res/android”
    android:layout_width=“匹配父级”
    android:layout_height=“匹配父级”
    android:orientation=“垂直”
    android:weightsum=“5”>
    片段
    安卓:id=“@+id/map”
    android:name=“com.google.android.gms.maps.supportMapFragment”
    android:layout_width=“匹配父级”
    android:layout_height=“0dp”
    android:layout_weight=“4”/>
    <水平滚动视图
    android:id=“@+id/horizontalscroll”
    android:layout_width=“匹配父级”
    android:layout_height=“0dp”
    android:layout_weight=“1”>
    
    <线性布局
    安卓:id=“@+id/ll”
    android:layout_width=“匹配父级”
    android:layout_height=“匹配父级”
    android:gravity=“中心”
    android:orientation=“水平”>
    </linearlayout>
    </HorizontalScrollView>
    </linearlayout>
    < /代码> 
    
    

    类文件:

    linearlayout linearlayout=(linearlayout)findViewByID(r.id.ll);
    对于(int v=0;v<collectioninfo.size();v++){
    /*-----------创建框架布局---------------------*/
    
    framelayout framelayout=新framelayout(activitymap.this);
    linearlayout.layoutParams layoutParams=new linearlayout.layoutParams(framelayout.layoutParams.wrap_content,getpixelstodp(90));
    layoutParams.rightMargin=getPixelsTodp(10);
    framelayout.setlayoutParams(layoutParams);
    
    /*——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————-*/
    
    /*-----------正在创建映像视图---------------------*/
    final imageview imgview=new imageview(activitymap.this);//动态创建imageview
    linearlayout.layoutParams lpimage=new linearlayout.layoutParams(linearlayout.layoutParams.wrap_content,linearlayout.layoutParams.wrap_content);
    imgview.setImageBitmap(collectionInfo.get(v.getcatimage());
    imgview.setlayoutparams(lpimage);
    //设置以后要检索的ID(与其位置相同)
    imgview.setid(v);
    imgView.setOnclickListener(new view.onclickListener()){
    @重写
    公共void onclick(视图V){
    
    //获取与其位置相同的ID
    log.i(标记,“clicked on”+collectioninfo.get(v.getid()).getcatname());
    //获取所选类别的数据列表
    new getSelectedCategoryData().execute(collectionInfo.get(v.getID()).getcatid());
    }
    (});
    /*------------图像视图结束---------------------------*/
    
    /*-----------正在创建文本视图---------------------*/
    textview textview=new textview(activitymap.this);//动态创建textview
    textView.settext(collectioninfo.get(v.getcatname());
    framelayout.layoutParams lptext=新framelayout.layoutParams(framelayout.layoutParams.wrap_content,framelayout.layoutParams.wrap_content,gravity.bottom_gravity.center);
    //注意:linearlayout.layoutParams的重力不起作用,因此我将framelayout设置为3 paramater是重力本身。
    textview.settextcolor(color.parsecolor(“43A047”));
    textview.setlayoutparams(lptext)设置;
    /*------------文本视图结束---------------------------*/
    
    //在适当的位置添加视图
    框架布局.addview(imgview);
    framelayout.addview(文本视图);
    linearlayout.addview(框架布局);
    
    }
    
    专用int getpixelstodp(int dp){
    float scale=getresources().getDisplayMetrics().density;
    int像素=(int)(dp*比例+0.5f);
    返回像素;
    }
    < /代码> 
    
    

    这里使用的技巧是我分配给ImageView“imgView.setID(v)”的ID,然后将onclickListener应用到该视图,我将再次获取该视图的ID……我在代码中也进行了注释,以便易于理解, 我希望这可能非常有用… 快乐编码…:

    这里的NSWER:https://stackoverflow.com/a/33301582/5479863

    我的JSON回复是:

    {"searchInfo":{"status":"1","message":"Success","clist":[{"id":"1de57434-795e-49ac-0ca3-5614dacecbd4","name":"Theater","image_url":"http://52.25.198.71/miisecretory/category_images/movie.png"},{"id":"62fe1c92-2192-2ebb-7e92-5614dacad69b","name":"CNG","image_url":"http://52.25.198.71/miisecretory/category_images/cng.png"},{"id":"8060094c-df4f-5290-7983-5614dad31677","name":"Wine-shop","image_url":"http://52.25.198.71/miisecretory/category_images/beer.png"},{"id":"888a90c4-a6b0-c2e2-6b3c-561788e973f6","name":"Chemist","image_url":"http://52.25.198.71/miisecretory/category_images/chemist.png"},{"id":"a39b4ec1-943f-b800-a671-561789a57871","name":"Food","image_url":"http://52.25.198.71/miisecretory/category_images/food.png"},{"id":"c644cc53-2fce-8cbe-0715-5614da9c765f","name":"College","image_url":"http://52.25.198.71/miisecretory/category_images/college.png"},{"id":"c71e8757-072b-1bf4-5b25-5614d980ef15","name":"Hospital","image_url":"http://52.25.198.71/miisecretory/category_images/hospital.png"},{"id":"db835491-d1d2-5467-a1a1-5614d9963c94","name":"Petrol-Pumps","image_url":"http://52.25.198.71/miisecretory/category_images/petrol.png"},{"id":"f13100ca-4052-c0f4-863a-5614d9631afb","name":"ATM","image_url":"http://52.25.198.71/miisecretory/category_images/atm.png"}]}}
    

    布局文件:

        <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:weightSum="5">    
        <fragment
            android:id="@+id/map"
            android:name="com.google.android.gms.maps.SupportMapFragment"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="4" />
        <HorizontalScrollView
            android:id="@+id/horizontalScroll"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1">
    
            <LinearLayout
                android:id="@+id/ll"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center"
                android:orientation="horizontal">    
            </LinearLayout>
        </HorizontalScrollView>
    </LinearLayout>
    

    类文件:

    LinearLayout linearLayout = (LinearLayout) findViewById(R.id.ll);
            for (int v = 0; v < collectionInfo.size(); v++) {
                /*---------------Creating frame layout----------------------*/
    
                FrameLayout frameLayout = new FrameLayout(ActivityMap.this);
                LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, getPixelsToDP(90));
                layoutParams.rightMargin = getPixelsToDP(10);
                frameLayout.setLayoutParams(layoutParams);
    
                /*--------------end of frame layout----------------------------*/
    
                /*---------------Creating image view----------------------*/
                final ImageView imgView = new ImageView(ActivityMap.this); //create imageview dynamically
                LinearLayout.LayoutParams lpImage = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
                imgView.setImageBitmap(collectionInfo.get(v).getCatImage());
                imgView.setLayoutParams(lpImage);
                // setting ID to retrieve at later time (same as its position)
                imgView.setId(v);
                imgView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
    
                        // getting id which is same as its position
                        Log.i(TAG, "Clicked on " + collectionInfo.get(v.getId()).getCatName());
                        // getting selected category's data list
                        new GetSelectedCategoryData().execute(collectionInfo.get(v.getId()).getCatID());
                    }
                });
                /*--------------end of image view----------------------------*/
    
                /*---------------Creating Text view----------------------*/
                TextView textView = new TextView(ActivityMap.this);//create textview dynamically
                textView.setText(collectionInfo.get(v).getCatName());
                FrameLayout.LayoutParams lpText = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.BOTTOM | Gravity.CENTER);
                // Note: LinearLayout.LayoutParams 's gravity was not working so I putted Framelayout as 3 paramater is gravity itself
                textView.setTextColor(Color.parseColor("#43A047"));
                textView.setLayoutParams(lpText);
                /*--------------end of Text view----------------------------*/
    
                //Adding views at appropriate places
                frameLayout.addView(imgView);
                frameLayout.addView(textView);
                linearLayout.addView(frameLayout);
    
            }
    
     private int getPixelsToDP(int dp) {
            float scale = getResources().getDisplayMetrics().density;
            int pixels = (int) (dp * scale + 0.5f);
            return pixels;
        }
    

    这里使用的技巧是我分配给ImageView“imgView.setID(v)”的ID,然后将onclickListener应用到该视图,我将再次获取该视图的ID……我在代码中也进行了注释,以便易于理解, 我希望这可能非常有用… 快乐编码…:)

    http://i.stack.imgur.com/lXrpG.png

        10
  •  5
  •   mobileideafactory    12 年前

    可以在支持库中使用RecyclerView。RecyclerView是支持以下功能的ListView的通用版本:

    • 用于定位项目的布局管理器
    • 常用的默认动画 项目操作

    Android Recycler View Docs

        11
  •  4
  •   Faisal    16 年前

    这不是一个很好的答案,但是使用 Horizontal Scroll View ?

        12
  •  3
  •   Community Mohan Dere    9 年前

    我做了很多寻找这个问题的解决方案的工作。简单的答案是,如果不重写私有方法之类的东西,就没有好的解决方案。我发现最好的办法是通过扩展 AdapterView . 真是惨不忍睹。看到我 SO question about horizontal ListViews .

        13
  •  3
  •   Sileria    13 年前

    我不得不为我的一个项目做同样的事情,结果我也写了自己的。我叫它 霍尔茨利特视图 现在是我的开放源码的一部分 无晶体的 图书馆。

    http://aniqroid.sileria.com/doc/api/ (在底部查找下载或使用谷歌代码项目查看更多下载选项: http://code.google.com/p/aniqroid/downloads/list )

    课程文档如下: http://aniqroid.sileria.com/doc/api/com/sileria/android/view/HorzListView.html

        14
  •  1
  •   Jorge Cespedes    11 年前

    对于我的应用程序,我使用一个包含内部线性布局的HorizontalScrollView,它的方向设置为Horizontal。为了在活动中添加图像,我在活动中创建了图像视图,并将它们添加到我的线性布局中。例如:

    <HorizontalScrollView 
            android:id="@+id/photo_scroll"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:scrollbars="horizontal"
            android:visibility="gone">
    
            <LinearLayout 
                android:id="@+id/imageview_holder"
                android:layout_width="wrap_content"
                android:orientation="horizontal"
                android:layout_height="match_parent">
    
            </LinearLayout>
        </HorizontalScrollView>
    

    A这个对我来说非常好。在活动中,我要做的就是下面的代码:

    LinearLayout imgViewHolder = findViewById(R.id.imageview_holder);
    ImageView img1 = new ImageView(getApplicationContext());
    //set bitmap
    //set img1 layout params
    imgViewHolder.add(img1);
    ImageView img2 = new ImageView(getApplicationContext());
    //set bitmap
    //set img2 layout params
    imgViewHolder.add(img2); 
    

    正如我所说,这对我很有用,我希望它也能帮助那些寻求实现这一目标的人。

        15
  •  0
  •   weakwire    16 年前

    好吧,你总是可以动态地创建你的文本视图等,并像使用适配器那样设置你的onclickListener。

        16
  •  0
  •   Community Mohan Dere    9 年前

    当适配器中的数据涉及到另一个线程时,HorizontiallistView无法工作。一切都在UI线程上运行100%,这是多线程中的一个大问题。我认为使用HorizontiallistView并不是解决问题的最佳方法。HorzListView是一种更好的方法。您只需将以前的库替换为HorzListView。您无需修改适配器的代码。然后一切都按您希望的方式进行。请参见 https://stackoverflow.com/a/12339708/1525777 关于HorzListView。

        17
  •  0
  •   Tiger    12 年前

    我曾经用过 horizontal listview link 在我的项目中,我得到了很好的结果。我已经习惯了 devsmart 图书馆一开始就给了我一些问题。所以最好的使用方法 水平列表视图链接 随着问题的解决,我最近在谷歌PlayStore上使用这个库发布了我的应用程序,得到了用户的好评。所以我建议您使用上面提到的同一个库水平显示ListView。享受:

        18
  •  0
  •   Muhammed Refaat    10 年前

    有一个很棒的图书馆,叫 TwoWayView ,它很容易实现,只需将项目库包含到您的工作空间中,并将其作为库项目添加到原始项目中,然后按照以下步骤操作 mentioned here :

    首先,我们添加一个指示ListView方向的样式。 (水平或垂直)in(res/values/styles.xml):

    <style name="TwoWayView">
        <item name="android:orientation">horizontal</item>
    </style>
    

    然后,

    在布局XML中,使用以下代码添加TwowayView:

    <org.lucasr.twowayview.TwoWayView 
         xmlns:android="http://schemas.android.com/apk/res/android"
         xmlns:tools="http://schemas.android.com/tools"
         xmlns:app="http://schemas.android.com/apk/res-auto"
         android:id="@+id/lvItems"
         style="@style/TwoWayView"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:drawSelectorOnTop="false"
         tools:context=".MainActivity" />
    

    最后,只需声明并像任何普通人一样处理它 ListView :

    TwoWayView lvTest = (TwoWayView) findViewById(R.id.lvItems);
    

    所有的方法 列表视图 会像往常一样在这里工作,但我注意到的唯一区别是,在设置选择模式时,方法 setChoiceMode 不采取 int 值,但值来自 enum 打电话 ChoiceMode 如此 list_view.setChoiceMode(ListView.CHOICE_MODE_SINGLE); lvTest.setChoiceMode(ChoiceMode.SINGLE); // or MULTIPLE or NONE .

        19
  •  -1
  •   Jeff Bootsholz    13 年前

    可以使用ViewFlipper包含布局XML并为每个布局XML添加图像、ListView。