-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Column count should depend on screen width, rather than orientation #148
Comments
why can't you define an integer resource |
@imminent I’m creating the grid programmatically, and |
You could set them both to the same dimen value, which uses the resource
|
@imminent can you describe further your solution (with some code for instance) |
@lawloretienne I’m not @imminent, but as the OP I would say yes :) |
res/values/integers.xml -> <integer name="grid_column_count">2</integer>
res/values-sw600dp-v14/integers.xml -> <integer name="grid_column_count">3</integer> then set the Grid View like so: <com.etsy.android.grid.StaggeredGridView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:column_count_landscape="@integer/grid_column_count"
app:column_count_portrait="@integer/grid_column_count" /> That way the column count only changes when the Integer resource changes (which in this case is on screen size) |
thanks @imminent i've end up to a similar solution that combines: |
Indeed, I just add this in my Fragment and it has been working like a charm! ^^
|
I have read #9 and #32. IMHO, width being greater or less than height (i.e. landscape or portrait respectively) has nothing to do with the optimum number of columns, since the grid is bounded horizontally, but not vertically. Instead, this value should be based solely on width, e.g.:
For a more concrete example, I find that my grid looks best:
1
column on a Nexus 4 portrait (384 dp
),2
columns on a Nexus 7 portrait (600 dp
), and3
columns in both Nexus 4 and Nexus 7 landscape (640 dp
and961 dp
respectively)In XML the corresponding setting could look like this:
And in code:
Here are the values if you don’t want single columns:
If you don’t like this proposal, in theory the same effect could be achieved “manually”, using only the current
setColumnCount
API.However, I would like to note that it seems broken. The orientation changes are handled correctly when using
setColumnCountPortrait
orsetColumnCountLandscape
, but usingsetColumnCount
leads to #70, #105, #134, #138.The text was updated successfully, but these errors were encountered: