I am working on an Android Advertisement SDK. This SDK will charge fetch Advertisement resource and play it in a WebView.
Depending on the content of the Advertisement, the SDK need to change the WebView's position and size. For Example, A banner advertisement will palce in the top or bottom of screen, some advertisement maybe place at center, left or right.
Now I need the users to place the WebView in FrameLayout, So I could change the position and size of WebView at will and don't affect other views. I could set FrameLayout.LayoutParameters to adjust position and size.
Obviously, this is a strong restriction for users. Maybe they want use RelativeLayout and others.
So is there anyone have ideas about my issue? I am trying to use fragment now and didn't know would it work.
There is 2 approach to do this.
One is to set a layout ( forgot the name ) which allows you to set a component at custom position, size anywhere you want. As I remember it was 2 of those and one is deprecated form a version of Android. Google it those please, if you choose this method.
Other one it is with a trick:
Establish 9 positions (like the 9 pinch) and there use a predefined layout.
For eg. use a Relative layout.
1. if the banner need to be in position 1 than do x,y,z stuff - rearrange a bit the others, do what you need if is on the top left.
2. if the banner it is a "merged position" 1 and 2 from grid (a a lot wider), than you do other corrections.
and do many cases what you need.
Good luck
I have figure out this question.
Every android app is base on a FrameLayout(android.R.id.content).When I need to change position of a view. I could remove the view from its current layout and add it to FrameLayout(android.R.id.content).
That's what I want.
Related
Which is the best option to create a responsive layout design? The first question is what should be the height and width of every view (it should be in percentage, match constraint or wrap content using constraint layout).
If we use wrap content I think there is no way to create a responsive design with help of wrap content because if content increase the view will take all the space of the screen either vertically or horizontally
If we use match constraint then, in that case, it's good, but sometimes it is looking awesome on Android Studio but when we run it on a real device it doesn't look the same
The last option is to use percentage, in that case, I think first we have to check our item list vertically and horizontally and provide them space according to their content priority and usage
So what will be the best case to create a responsive layout in XML for Android?
It depends on UI.generaly people use the 2nd and 3rd methods because by using constraints and percentages you can get responsive UI.
sometimes it depends on your requirement.
if you are using the percentage method and you set the imageView at 10 % it's looking proper on your device but sometimes it happened that in a small device that imageView is not looked proper
So the moral is all your three methods can be applied as per UI you can not make all designs responsive using 1 method
I've been looking for a solution to my problem for weeks, and can't find out anything close to what I want. I need a big grid something at least 10000x10000 and even more if I can. The objective is to change the color of the cell that have been clicked. To do so users should be able to zoom in and click in one cell to modify it color. Then obviously zoom out.
I first thought to pick an image and make it clickable but to change the color of only 1 cell it would be impossible in an image.
Then I tried to do a grid with buttons inside and change their color on click, but way to long to create those inside the content page, same for labels.
Any suggestion ?
Thanks for reading
I don't believe you can do this with existing UI & Layout controls.
It will be extremely slow and hard to do.
You should use a graphic library such SkiaSharp. Here is a good tutorial to do it.
You might use pan & pinch gesture for zooming as well(howto).
I'm stuck and I think wisdom (aka experience) is the only solution.
I need to be able to have boxes on a screen with data inside each box. The number of boxes on the screen needs to be able to change and the boxes need to scale accordingly (as well as the text data inside of them) to allow for the additional boxes.
Example: I might start with only 8 boxes which are evenly spaced and displaying data at a reasonable font scale.
As I add more boxes I need the rest of the boxes to scale down and allow everything on one screen.
I am currently attempting to use a TableLayout, but I'm not certain how to make everything scale correctly. Also, I'm generating everything programmatically by extending the TableLayout. Can someone point me in the right direction. Is there a better layout method that I'm not seeing? I'm sure I'm not the first person to need this, so are there examples available that I'm just not finding by searching?
The eventual solution was to build my own scaling function which took screen pixel dimensions and calculated the appropriate margin offsets to use on a relative layout. It requires a complete redraw each time the scaling factor changes, which is annoyingly resource intensive.
I've one of the simplest layouts imaginable: A num pad.
I want to create a fragment containing a 3 x 4 grid of buttons. The layout should automatically resize the num pad to fill the available space.
I've learned, that GridLayout is not up to the task, and TableLayout/TableRow or nesting LinearLayouts means nesting weights, which is also discouraged for performance reasons. A RelativeLayout won't work either, because that requires at least one button with given dimensions.
So, is there a clean way to create a regular grid that will resize to fill its parent?
Any help is appreciated, thx!
You will need a custom compound control.
Check the following link:
http://developer.android.com/guide/topics/ui/custom-components.html#compound
Make the control fill the available space. Make it to have 12 buttons. Calculate the size and position of them based on their position and the available space.
Depending on your needs you might also need to override onMeasure() and onLayout() defined earlier in the above document, in the "Fully Customized Components" section.
I am fairly new to android and am having some problems with a layout. Below is an approximation of what I want the layout to look like. (I would like the list to be below the screen at first so that the user can scroll down to see it.) However my code as it currently stands makes all of the views on the left only take up a quarter the screen instead of half, as depicted, even though I have all widths set to fill_parent.
Also, this layout seems to mess up the coordinate system on my custom view. Normally this wouldn't be much of an issue, but in this case I am using that view to draw a picture and the picture ends up in the wrong place. Does anybody have any idea how to resolve these issues?
Could you show the XML file you are using? This would be helpful. Also, the coordinate system of a View does not change based on the layout.