显示线性布局的水平滚动图。 [英] Displaying horizontal scrolling view of a linear layout.

查看:200
本文介绍了显示线性布局的水平滚动图。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个文本描述和一个按钮图像的水平滚动视图。

I would like to create a horizontally scrolling view of an image with text description and a button.

在列表中的每个条目将占据整个屏幕左侧的图片和一些描述性文字的,正确的。滚动向左或向右移动将整个视图在一个屏幕沿并显示一个画面和文字。

Each entry in the list will take up the entire screen with a picture on the left and some descriptive text to the right of that. Scrolling left or right will move the entire view one screen along and display the next picture and text.

什么是显示这样的数据的最佳方式?

What is the best way to display such data?

谢谢,
中号

推荐答案

确定,这里是实现我所希望做的一种方式。我最初把这个从 http://geekyouup.blogspot.com/ 2011/07 / viewpager - 例如从 - paug.html 但我想不止一个的TextView添加到滚动列表。

OK, here is a way to implement what I was looking to do. I initially took this from http://geekyouup.blogspot.com/2011/07/viewpager-example-from-paug.html but I wanted to add more than one textView to the scrolling list.

我是在第一次奋力包含比一个文本查看更多
 这显示在这个网站上的演示,但它是由于铸造然后向TextView的在destroyItem和initemfromObject方法。我打算写一PagerCurrsor适配器源码,所以我会当我得到它的工作后在这里。

I was struggling at first to include more than the one text view which is shown in the demo at this site but it was because of then Casting to TextView in the destroyItem and initemfromObject methods. I'm going to be writing a PagerCurrsor adapter for sqlite so I'll post it here when I get it working.

另外需要注意的是,用户通过刷卡清单,因此会使用通过数组或游标来遍历该位置递增。

Another thing to note is that position is incremented as the user swipes through the list so you would use that to iterate through an array or a cursor.

希望这有助于其他开发人员和感谢张贴的所有答案。

Hope this helps other developers and thanks for all the answers posted.

Overidden方式:

Overidden methods:

        public Object instantiateItem(View collection, int position) {

            layout = inflater.inflate(R.layout.scrolllayout, null);
            TextView tv = (TextView) layout.findViewById(R.id.textView1);
            tv.setText("1________________>" + position);

            TextView tv2 = (TextView) layout.findViewById(R.id.textView2);
            tv.setText("2________________>" + position);

            ((ViewPager) collection).addView(layout);
            return layout;
        }


            @Override
            public void destroyItem(View collection, int position, Object view) {
                    ((ViewPager) collection).removeView((View)view);
            }



            @Override
            public boolean isViewFromObject(View view, Object object) {


               return view==((View)object);
            }

XML:

  <?xml version="1.0" encoding="utf-8"?>
  <LinearLayout
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:id= "@+id/container" 
   android:layout_width="match_parent"
   android:layout_height="match_parent" android:orientation="vertical">

     <TextView android:layout_width="wrap_content" android:layout_height="wrap_content"        android:text="TextView1"  android:id="@+id/textView1"></TextView>
     <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView2"  android:id="@+id/textView2"></TextView>
   </LinearLayout>

[1] http://geekyouup.blogspot.com/2011/07/viewpager-example-from-paug.html

[1]http://geekyouup.blogspot.com/2011/07/viewpager-example-from-paug.html

这篇关于显示线性布局的水平滚动图。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆