Scrolling Scrolling for Android

This is more a mass answer than a question, I just don’t know how to publish it as such, moderators, if you could tell me if there is even such a thing.

This question was asked to death, and then I needed to do something similar, so I worked it out. Answer to this post: how to create 3x3 bidirectional scroll view in android

+4
source share
1 answer

The following describes how to create a bidirectional scroll view.

Put a gallery in a GridView with the same column and column size to populate the parent view (or something like that). Place the gallery in the GridView and set its height in LayoutParams to the height of the drawings / views you want to occupy. All you have to do is when one gallery moves to move all the others in a grid. I will send the code below. Note: the code I made is a concept test that works, I just tried it on my phone. However, it is not flashy. As I continue to work on it, I can update the code to make it look better.

~ Aedon :)

This is a general answer to questions such as: How to make a 2-dimensional image gallery with horizontal and vertical scrolling?

GridView with horizontal scroll

public class Test extends Activity { /** Called when the activity is first created. */ GridView gv; Gallery g[] = new Gallery[3]; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); gv = (GridView)findViewById(R.id.gridview); gv.setAdapter(new GAdapter()); for (int i = 0; i < g.length; i++) { g[i] = new Gallery(this); g[i].setAdapter(new GGAdapter()); g[i].setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View arg0, MotionEvent ev) { if (ev.getAction() == MotionEvent.ACTION_UP) { for (int j = 0; j < g.length; j++) { g[j].setSelection(((AdapterView)arg0).getSelectedItemPosition()); } } return false; } }); } } private class GAdapter extends BaseAdapter { public GAdapter() {} @Override public int getCount() {return g.length;} @Override public Object getItem(int pos) {return pos;} @Override public long getItemId(int pos) {return pos;} @Override public View getView(final int pos, View convertView, ViewGroup parent) { g[pos].setLayoutParams(new GridView.LayoutParams(gv.getWidth(), gv.getHeight())); return g[pos]; } } private class GGAdapter extends BaseAdapter { int[] images = new int[] {R.drawable.icon, R.drawable.icon, R.drawable.icon}; public GGAdapter() {} @Override public int getCount() {return images.length;} @Override public Object getItem(int pos) {return pos;} @Override public long getItemId(int pos) {return pos;} @Override public View getView(final int pos, View convertView, ViewGroup parent) { ImageView mIV = new ImageView(Test.this); mIV.setBackgroundResource(images[pos]); mIV.setLayoutParams(new Gallery.LayoutParams(gv.getWidth(), gv.getHeight()/3)); return mIV; } } 

}

and my xml file:

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <GridView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/gridview" android:layout_width="fill_parent" android:layout_height="fill_parent" android:numColumns="1" android:verticalSpacing="10dp" android:horizontalSpacing="10dp" android:gravity="center"/> </LinearLayout> 
+2
source

Source: https://habr.com/ru/post/1335314/


All Articles