change LinearLayoutManager to GridLayoutManager - gridlayoutmanager

private void setUpRecyclerView() {
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerViewAdapter = new StoryAdapter(MainActivity.this, getData());
recyclerView.setAdapter(recyclerViewAdapter);
recyclerViewAdapter.notifyDataSetChanged();
}
private ArrayList<Object> getData() {
Good someone helps me implement gridlayoutmanager?
1 Photo so I have it
https://i.imgur.com/d9sPssi.png
2 photo so I want to leave someone can help me?
https://i.imgur.com/VyIZwPe.png
enter image description here
I leave the code in the comments thanks.

Take a look here - https://medium.com/#alla.dubovska/android-recyclerview-animated-transition-between-grid-and-list-layouts-b2309e1d9f19
This article is about RecyclerView animated transition between Grid and List layouts.

Related

Xamarin.Android, top bar, how add shortcut button ON/OFF

enter image description hereI can't find way to add button with icon to top screen menu. I don't even know name of this bar. I mean swiping down of top screen menu however your are, there are buttons like wifi, bluetooth, screen etc.(picture attached). Maybe someone know name of this bar, link to sdk or how add this button or something connected to it.
It is the Tile Service for the quick settings in the Android, you can check the official document about this.
In addition, I have done a sample to test this api and it worked well.
Just declare a class to extend the TileService, such as:
[Service(Permission = "android.permission.BIND_QUICK_SETTINGS_TILE", Icon = "#drawable/icon", Label = "mymenu", Enabled = true, Exported = true)]
[IntentFilter(new[] { "android.service.quicksettings.action.QS_TILE" })]
public class DemoTitle : TileService
{
public override void OnClick()
{
refresh();
}
public void refresh()
{
var state = QsTile.State;
state = (state == TileState.Active)?TileState.Inactive:TileState.Active;
QsTile.State = state;
QsTile.UpdateTile();
}
}
After this, you can find and add the your custom button to the quick settings when you click the editing button in the bar.

Text overlapping on Xamarin.IOS table

As I said in other questions I am very newbie in .Net technologies. Now I am starting with an exercise using the Xamarin Crossplatform (Xamarin.IOS for the moment). But I have a problem with this code, it's working, but the method ForceUpdateSize() crashes the application if I have more than 6 elements in the table?. When I remove the method the app works fine, but then the text is overlapped.
This is the method that is filling my table:
public sealed class AutoViewCellRenderer : ViewCellRenderer
{
public override UITableViewCell GetCell(Cell item, UITableViewCell reusableCell, UITableView tv)
{
ViewCell vc = item as ViewCell;
if (vc != null)
{
var sr = vc.View.Measure(tv.Frame.Width, double.PositiveInfinity, MeasureFlags.IncludeMargins);
if (vc.Height != sr.Request.Height)
{
sr = vc.View.Measure(tv.Frame.Width, double.PositiveInfinity, MeasureFlags.IncludeMargins);
vc.Height = sr.Request.Height;
//vc.ForceUpdateSize(); --> Text ovelpping effect if I remove this method, but the app doesn't crash
}
}
return GetCell(item, reusableCell, tv);
}
}
Can someone help me to understand what I am doing wrong?
Thanks in advance to everybody!
Try this:
//vc.ForceUpdateSize(); --> Text ovelpping effect if I remove this method, but the app doesn't crash
tv.BeginUpdates();
tv.EndUpdates();
I have found this in an older post, but sadly I can't find it anymore.
Also take a look at this: https://github.com/xamarin/Xamarin.Forms/issues/4012
I think the Xamarin Community knows well about this and is addressing it in this Thread.

How to preview a links in Recyclerview

I need to preview links of pages in recyclerview . I used this Library : https://github.com/LeonardoCardoso/Android-Link-Preview but it does not work. anyone know another way ?
Based on our chat in the comments section, you want to add the preview at some position in your scroll list. In that case, you can maintain some state (eg. position) in LinkPreviewCallback. So that when the preview results are ready, based on the maintained state, you can find the exact view where preview needs to be rendered.
Create a Class and Implement LinkPreviewCallback.
class MyPreviewCallback implements LinkPreviewCallback {
int position;
public MyPreviewCallback(int position) {
super();
this.position = position;
}
#Override
public void onPre() {
}
#Override
public void onPos(SourceContent sourceContent, boolean b) {
// update adapter list item based on the position.
}
}
Pass callback to the crawler.
textCrawler.makePreview(new MyPreviewCallback(3), url); // passing position
The main idea is basically to maintain some state in your class which will let you identify the exact View to be updated with Preview.

A problem with a randomly coloured background

I use StackOverflow for the first time, so please be friendly and understanding.
Few days ago I got interested in ActionScript. I have downloaded FlashDevelop (a free IDE) and FlexSDK4. Then I have learned the basics from some tutorials.
For now I am not really developing any big project, I'm rather just doing tests.
Anyway, a solution to my problem is really important for me. I have looked for it, but I couldn't find any.
I have just one button and a background in my app. Both the button and the background (below: "bg") are objects of the Sprite class.
When I click the button, the background gets painted with 10x10px squares of random colours.
The problem is that the more times I click the button, the longer time I have to wait until the background changes. And that's not all! I can change the background exactly 54 times! At the 55th time it doesn't change at all.
package {
// some imports here
public class Main extends Sprite {
private var button:Sprite;
private var bg:Sprite;
public function Main ():void {
init();
}
private function init (e:Event=null):void {
addChild (bg);
// in the original code there are some lines here,
// in which the button is created
addChild (button);
button.addEventListener (MouseEvent.CLICK, btnClick);
}
private function btnClick (event:MouseEvent):void {
var x:uint, y:uint, color:uint;
for (y=0; y<30; y++) {
for (x=0; x<40; x++) {
color=Math.round(Math.random()*16777215);
bg.graphics.beginFill (color);
bg.graphics.drawRect (x*10, y*10, 10, 10);
bg.graphics.endFill ();
}
}
}
}
}
The code is so short, because I have removed many void lines. I have left only the important ones.
What is wrong with this code? Please help me.
Thanks in advance.
clear your graphics before the loop
var x:uint, y:uint, color:uint;
bg.graphics.clear();
for (y=0; y<30; y++) {//etc

How do I 'addChild' an DisplayObject3d from another class? (Papervision3d)

Im kind of new in the whole papervision scene.
For a school assignment I'm making a panorama version of my own room using
a cube with 6 pictures in it. It created the panorama, it works great.
But now I want to add clickable objects in it. One of the requirements
is that my code is OOP focused. So that's what I am trying right now.
Currently I got two classes
- Main.as (Here i make the panorama cube as the room)
- photoWall.as (Here I want to create my first clickable object)
Now my problem is: I want to addChild a clickable object from photoWall.as
to my panorama room. But he doesn't show it? I think it has something to do with
the scenes. I use a new scene in Main.as and in photoWall.as. No errors or warnings are reported
This is the piece in photoWall.as were I want to addChild my object (photoList):
private function portret():void
{
//defining my material for the clickable portret
var material : BitmapFileMaterial = new BitmapFileMaterial('images/room.jpg');
var material_list : MaterialsList = new MaterialsList( { front: material, back: material } );
// I don't know if this is nessecary? that's my problem
scene = new Scene3D();
material.interactive = true;
// make the clickable object as a cube
var photoList : DisplayObject3D = new Cube(material_list, 1400, 1400, 1750, 1, 4, 4, 4);
// positioning
photoList.x = -1400;
photoList.y = -280;
photoList.z = 5000;
//mouse event
photoList.addEventListener( InteractiveScene3DEvent.OBJECT_CLICK, onPress);
// this is my problem! I cannot see 'photoList' within my scene!!!
scene.addChild(photoList);
// trace works, so the function must be loaded.
trace('function loaded');
}
Hope you guys can help me out here. Would really be great!
Thanks,
Sandor
you have to render before you can se anything.
missing:
viewport.startRender()
No I already rendered everything in another class.
I figured it out, the answer is: I have to make this class a displayobject3d.
that's it. everything you addchild on the stage now is a displayobject3d.
for details or code..just ask.
view the result of my little project here :
http://www.sandorkerst.com/papervision/bin

Resources