grid view picture puzzle formation error in android - android

i.setLayoutParams(new GridView.LayoutParams(iwidth , iheight ));
i.setImageBitmap(duplicate.get(arg0));
i.setPadding(1, 1, 1, 1);
I am using the above to provide spaces actually i'm splitting an image and using gridview for placing the splitted images in gridview allowing the user to play picture puzzle in grid view but the splitted images are not fitted exactly in grid view the moddle row images are shrink and the right side images are enlarged one more issue is spacing between them ,it is providing spaces as from one row to next row but it's not providing spaces column to column can any one help me

I just looked at the docs and there's a setVerticalSpacing() and a setHorizontalSpacing() methods. Check them out.
So instead of setting the spacing in the ImageView, you can set it at the grid level.

Related

Horizontally and vertically scrollable layout in react native

I am trying to configure table grid layout in react native which could be scrollable horizontally and vertically.
By table grid layout I mean the layout similar to html table/tr/td: all views in the same row should have the same height and all views in the same column should have the same width.
The height of the row should be selected based on the height of the biggest view in the row.
The width of the column should be selected based on the width of the biggest view in the column.
I've started with horizontal scrolling.
This is what I've done:
https://snack.expo.io/#grekonstudio/01_initial
While it looks fine for me in the browser, on my device in looks this way:
The biggest column takes as much space as it needs and the rest of the space is shared between other columns. But it is done for each row independently, so columns border floats. Ideally, I want Row 1, Col 1 and Row 2, Col 1 to be the same size as Row 3, Col 1. That does not work as they and in different rows.
Well, obvious idea is to switch to column base layout, right:
https://snack.expo.io/#grekonstudio/04_column_based
Again, in the browser, it looks different. On the device it looks this way:
On the first look, this is exactly what I want! But apparently, it just moves the problem to another dimenstion. Let's make one View higher than the others, add a vertical ScrollView and we are losing row layout now:
https://snack.expo.io/#grekonstudio/05_same_problem
You can see the bigger cell takes all space and the rows are not having the same size anymore :(
Additionally, I tried two more things:
setting the flex: 1 to Scroll's view contentContainerStyle.
https://snack.expo.io/#grekonstudio/02_flex_1
In this case, it does not scroll at all.
Getting device height and width and fixing the size of the scroll view contentContainerStyle
https://snack.expo.io/#grekonstudio/03_fixed_width
In this case 'flex: 1' works as it works without a scroll view: splitting it to equal size boxes, while I want rows and cols to be adjusted by content
Another disadvantage is hardcoding width: 2 * screenWigth as e.g. for small content I might not need 2 screen width, I might need 1.5 or 1.2 only. It would also not work in portrait easlity.
I've also tried using the DataTable component https://callstack.github.io/react-native-paper/data-table.html, but when added to horizontal scroll view it fails to keep table layout the same way as in my first image: cells in the same column have different width.
Does anyone have a solution for the above?

Dynamically change the size of cells and spacing in grid layout android

I have a textview inside a grid layout and I want to change the size of grid cells according to the text area of the text view. If the word size is 5, then the grid size will be calculated accordingly. I am adding both the textview and the grid dynamically. I used the below code for this text area calculation,
text[i].setText(String.valueOf(finallist.get(i)));
text[i].measure(0, 0);
int widths = text[i].getMeasuredWidth();
params.width=widths;
text[i].setLayoutParams(params);
text[i].setTextSize(10);
where 'params' is the layout params for the textview. When I run this code, I am getting output as shown below.
Here I am getting extra spaces in between the grids no matter the textview size is wrapped. Instead I wanted the grid layout to occupy the area if it's available. I wanted the output like this,
I wanted equal spacing between the grids. How can I achieve this DYNAMICALLY .Also I am implementing drag and drop here. I am new to this. Please help. Thanks in advance.
Use StaggeredGridLayoutManager instead of normal GridLayout. A good example of Staggered Grid layout manager will be found here.
A LayoutManager that lays out children in a staggered grid formation. It supports horizontal & vertical layout as well as an ability to layout children in reverse. Staggered grids are likely to have gaps at the edges of the layout. To avoid these gaps, StaggeredGridLayoutManager can offset spans independently or move items between spans. You can control this behavior via setGapStrategy(int).
Hope it helps. Cheers!
you can use GridLayout.Spec as it has both rowSpec and columnSpec properties.Also try setAlignmentMode asit used for all of the alignments between the children of its container.
You should consider FlexboxLayout. Take a look at the readme at the GitHub project site. I think you will find that it will fit your needs. There is also a FlexboxLayoutManager for RecyclerView. This is all supported by Google.

GridView Header and Footer with header filled the screen width

Hi I am working on GridView which has header and footer.
In my case, the header's width should fill the screen width like below
But I am getting the header filled the grid items' width.
I have used the library.
What should I have to do to make the header's width match with screen width.
Note : The header only should filled the screen width not the grid items. And the grid items should have right and left margins.
Use the HFGridview
`https://github.com/SergeyBurish/HFGridView/tree/master/HFGridView
By this you will acheve waht you want with little bit customisation. I already implemented that. If you face any problem let me know I will share code with you.

Create custom Gridview with images of variable width and height

I want to create Grid view like Google plus which arranges images in variable width and height in the layout. For example say i have 7 images, and these images should be arranged in the grid view( Not in regular grid view but with variable rows and columns). These images should change their position in grid view after sometime say 5 seconds.

How to set the x position of views in android

I am creating a number of imageviews and textviews on runtime depending on the objects in my webservice. I'm creating linearLayout horizontal and adding imageviews and textviews to layout, now the issue is the text are against images, and images are of different width so i want to set x position of my textviews so they all look align how can this be done,
i tried absolutelayout(warning deprecated) , setx(no method showed)
you can use resized image on runtime based on the pannel height and width for resizing image on runtime view this stack overflow thread
resizing image java getScaledInstance
I presume you mean this is a vertical LinearLayout, and each text/image combo is added below the previous one? In that case, you could have two LinearLayouts next to each other like two columns, adding the images to one and the text fields to the other. Then the widest image would stretch its layout to that width and all text fields would be just to the right of it.
Use weight property in your ImageView and TextView

Categories

Resources