English 中文(简体)
我如何能够在安乐斯发表横向名单? [复制]
原标题:How can I make a horizontal ListView in Android? [duplicate]
This question already has answers here:
Closed 10 years ago.

Possible Duplicate:
Horizontal ListView in Android?

和安乐斯的许多事情一样,你不认为这是一个如此棘手的问题,但用刚果语说,你会错。 如同安的很多事情一样,安普森甚至提供了合理的切入点。 如果我能亲自提出我自己的名单的话,那么我就会大声疾呼,而我却要把这.倒。 ant

奥凯,现在我做了大量的工作,让我谈谈问题本身。 我需要的基本上是像<条码>Gallery那样的,但没有中心锁定特征。 我不需要<代码>。 ListView s listSelector but it s a nice-to-have. 多数情况下,我可以采用<代码>LinearLayout。 观点,但我需要儿童的意见来自<条码>。 页: 1 不想书写任何排外法。

I peeked into the source Code for some of these levels...

Gallery: 如果我凌驾于大多数的Xyz方法之上,照抄所有来源代码,但不要打<条码>。 但我确信,如果我这样做的话,我会跑到某些成员领域,造成无法接近或某些其他意外后果。

AbsSpinner: 由于<代码>mRevolr 外地是包件-私的,我怀疑我能够延长这一类别。

AbsListView: 它认为,这一类只是垂直滚动,因此没有帮助。

Adapter 观点: 我从未直接延长这一类别。 如果你告诉我,很容易去做,并且很容易推出我自己的<代码>Reillibin,那么,我就听起来很冷静,但我只给我一枪。

我可以申请复制AbsSpinnerGallery,以获得我所希望的东西。 所有人是否认为这是一种良好做法? 是否有任何辅导或第三方解决办法使我走上正确的方向?

Update:
The only solution I ve found so far is to do it all myself. Since asking this question, I have overridden AdapterView and implemented my own "HorizontalListView" from scratch. The only way to truly override the Gallery s center-locking feature is to override the private scrollIntoSlots method, which I believe would require generating a subclass at runtime. If you re bold enough to do that, it s arguably the best solution, but I don t want to rely on undocumented methods that could change.

下面的SwathiEPA建议,我提供<代码>Gallery的,并优先于滚动功能。 如果你不关心在你名单上有点支持,或者如果你在唱歌结束时向中心提出看法,那么,你的工作就是: 然而,最终仍然证明,如果不消除隔热支持,就不可能消除中心锁的特征。 我问你,哪一类名单 f?

因此,这不是为了我工作: 但是,如果你重新对这种做法感兴趣,就读到......。

我还必须对Swathi的法典作一些补充,以了解我想要的东西。 在<代码>GestureListener.on Touch中,除了被授权到姿态探测器之外,我还必须返回<代码>ACTION_UP和ACTION_CompL活动。 这成功打破了中心锁定的特征,但也造成了残疾。 我通过让我自己的GestureListener代表到美术厅onFling,得以重现。 如果你想尝试,就进入你ApiDemos的样本代码,用以下代码取代美术1.java的类别:

import com.example.android.apis.R;

import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.GestureDetector;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.View.OnTouchListener;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.Toast;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener;

public class Gallery1 extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.gallery_1);

        // Reference the Gallery view
        final Gallery g = (Gallery) findViewById(R.id.gallery);

        // Set the adapter to our custom adapter (below)
        g.setAdapter(new ImageAdapter(this));

        // Set a item click listener, and just Toast the clicked position
        g.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView parent, View v, int position, long id) {
                Toast.makeText(Gallery1.this, "" + position, Toast.LENGTH_SHORT).show();
            }
        });

        // Gesture detection
        final GestureDetector gestureDetector = new GestureDetector(new MyGestureDetector(g));
        OnTouchListener gestureListener = new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                boolean retVal = gestureDetector.onTouchEvent(event);
                int action = event.getAction();
                if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
                    retVal = true;
                    onUp();
                }
                return retVal;
            }

            public void onUp() {
                // Here I am merely copying the Gallery s onUp() method.
                for (int i = g.getChildCount() - 1; i >= 0; i--) {
                    g.getChildAt(i).setPressed(false);
                }
                g.setPressed(false);
            }
        };
        g.setOnTouchListener(gestureListener);

        // We also want to show context menu for longpressed items in the gallery
        registerForContextMenu(g);
    }

    @Override
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
        menu.add(R.string.gallery_2_text);
    }

    @Override
    public boolean onContextItemSelected(MenuItem item) {
        AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
        Toast.makeText(this, "Longpress: " + info.position, Toast.LENGTH_SHORT).show();
        return true;
    }

    public class ImageAdapter extends BaseAdapter {
        int mGalleryItemBackground;

        public ImageAdapter(Context c) {
            mContext = c;
            // See res/values/attrs.xml for the <declare-styleable> that defines
            // Gallery1.
            TypedArray a = obtainStyledAttributes(R.styleable.Gallery1);
            mGalleryItemBackground = a.getResourceId(
                    R.styleable.Gallery1_android_galleryItemBackground, 0);
            a.recycle();
        }

        public int getCount() {
            return mImageIds.length;
        }

        public Object getItem(int position) {
            return position;
        }

        public long getItemId(int position) {
            return position;
        }

        public View getView(int position, View convertView, ViewGroup parent) {
            ImageView i = new ImageView(mContext);

            i.setImageResource(mImageIds[position]);
            i.setScaleType(ImageView.ScaleType.FIT_XY);
            i.setLayoutParams(new Gallery.LayoutParams(136, 88));

            // The preferred Gallery item background
            i.setBackgroundResource(mGalleryItemBackground);

            return i;
        }

        private Context mContext;

        private Integer[] mImageIds = {
                R.drawable.gallery_photo_1,
                R.drawable.gallery_photo_2,
                R.drawable.gallery_photo_3,
                R.drawable.gallery_photo_4,
                R.drawable.gallery_photo_5,
                R.drawable.gallery_photo_6,
                R.drawable.gallery_photo_7,
                R.drawable.gallery_photo_8
        };
    }

    public class MyGestureDetector extends SimpleOnGestureListener {

        private Gallery gallery;

        public MyGestureDetector(Gallery gallery) {
            this.gallery = gallery;
        }

        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, 
                float velocityY) {
            return gallery.onFling(e1, e2, velocityX, velocityY);
        }
    }

}
问题回答

在阅读这一职位后,我实施了我自己的横向。 http://dev-smart.com/horizontal-listview/"rel=“nofollow”http://dev-smart.com/horizontal-listview/。 让我知道这是否有助于。

您是否考虑使用HorizontalScrollView,以总结您的清单内容? 这将使您的每个清单项目能够横向地滚动(你们在清单中说的是什么,并且能够使其具有类似于《清单》的活力。 如果你只是经过一整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整整的物品。

您知道,ight 有可能使用现有清单,对<条码>发送/代码>(以90度取代Canvas)、on Touch((移至Event coords的X和Y条)和可能位于Measure(或以x而不是x到......)的思考。

如果能实际工作,我没有想法,但可以发现:

这可能是一个很晚的答复,但它正在为我们工作。 我们正在使用安乐斯提供的同样的彩礼,只是我们调整了左边,使左边的屏幕被视为美术中心。 这对我们来说确实是行之有效的。

美术是最佳解决办法,就是尝试。 我在一份邮递上工作,在邮箱中,邮递作为名单显示,我想持横向观点,即把邮单转换为包裹,所有邮件都按需要做罚款,没有任何错误。 滚动效应一使雕像的聆听器能够收听。 我希望这一答案能够帮助。

您是否研究了“观点反馈”的内容? 或许可以帮助你们。

rel=“nofollow” http://developer.android.com/vis/android/widget/ViewFfaller.html

有了这个组成部分,你可以照顾两个或两个以上的孩子。 如果你补充一些解释,了解地质构造的探测,那么你可以拥有一种冰层的横向滚动。

我在评估中使用了《港务》中的一份清单,该清单只是以地貌方式转至美术馆。 两人都使用一个基地Adapter。 如下所示。

       setContentView(R.layout.somelayout);
       orientation = getResources().getConfiguration().orientation;

       if ( orientation == Configuration.ORIENTATION_LANDSCAPE )
       {

            Gallery gallery = (Gallery)findViewById( R.id.somegallery );

            gallery.setAdapter( someAdapter );

            gallery.setOnItemClickListener( new OnItemClickListener() {
            @Override
            public void onItemClick( AdapterView<?> parent, View view,
                    int position, long id ) {

                onClick( position );
            }
        });
       }
       else
       {
            setListAdapter( someAdapter );

            getListView().setOnScrollListener(this);
       }    

To handle scrolling events I ve inherited my own widget from Gallery and override onFling(). Here s the layout.xml:

    <view 
    class="package$somegallery"
    android:id="@+id/somegallery" 
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent">
    </view>

准则:

    public static class somegallery extends Gallery
    {
        private Context mCtx;

        public somegallery(Context context, AttributeSet attrs)
        {
            super(context, attrs);
            mCtx = context;
        }

        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
                float velocityY) {

            ( (CurrentActivity)mCtx ).onScroll();

            return super.onFling(e1, e2, velocityX, velocityY);
        }
   }




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签