Is it possible to load items in GridView with vertical orientation? I mean...
Normal situation - 3 columns
I don't think this is possible at all.
Reason ::
I did some work on this and came to this conclusion.Hope this make unanswered question answered.
If you are using GridLayoutManager with RecyclerView, easy way to fill vertically data first is :
GridLayoutManager lLayout_artist = new GridLayoutManager(getActivity(),3,GridLayoutManager.HORIZONTAL, false);
You can change orientation of GridLayoutManager as per your requirement.
// Have you ever used GridLayout this, Try this one:
File -> Import -> <sdk_folder>\extras\android\support\v7\gridlayout>
// Add this project as library project
// xml file - activity_main.xml
<android.support.v7.widget.GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/gridLayout"
tools:context="com.example.gridlayoutdemo.MainActivity" >
</android.support.v7.widget.GridLayout>
// Java code
MainActivity.class
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.GridLayout;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends ActionBarActivity {
private GridLayout gridLayout;
private TextView[] textViews;
private int noOfItems;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gridLayout = (GridLayout) findViewById(R.id.gridLayout);
gridLayout.setOrientation(1);
gridLayout.setColumnCount(3);
gridLayout.setRowCount(3);
textViews = new TextView[8];
for (int i = 0; i < 8; i++) {
textViews[i] = new TextView(MainActivity.this);
textViews[i].setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
textViews[i].setText(String.valueOf(i));
textViews[i].setTextSize(25);
textViews[i].setPadding(50, 25, 10, 25);
gridLayout.addView(textViews[i]);
}
setContentView(gridLayout);
for (noOfItems = 0; noOfItems < 8; noOfItems++) {
textViews[noOfItems].setOnClickListener(new View.OnClickListener() {
int pos = noOfItems;
public void onClick(View v) {
Toast.makeText(getBaseContext(), pos + " Clicked",
Toast.LENGTH_SHORT).show();
}
});
}
}
}
// If you want to display horizontally than do this gridLayout.setOrientation(0);
Please clarify, say you have a Grid like this
1 4 7
2 5 8
3 6 9
now if you scroll it down vertically, it should basically be like this??
2 5 8
3 6 9
4 7 10
In this case,
Clearly, this is not how a normal ListView/GridView works where a row is recycled at a time, AFAIK you will need to customise GridView to get this functionality.
Is it possible to change the sequence of data? In your example, change data to [1,3,5,2,4,6, ...] for horizontal orientation, [1,5,2,6,3,7,4,8, ...] for vertical orientation.
I think you need https://github.com/ApmeM/android-flowlayout . and set child gravity to Gravity.FILL_HORIZONTAL
they even have vertical
or horizontal
orientation