[Q] Resize a linearlayout in an appwidget from code - Android Software Development

is it possible? I have created a unique sort of clock as an AppWidget that has horizontal bars that should indicate minutes and hours. How could I change the width of the LinearLayout used as a bar from the onUpdate() method? I tried RemoteViews but that Views seems to lack a setWidth() method...

appwidgets are unlike anything else in android. they cannot directly alter, add, or remove items from a layout. the only thing that can be altered is text in a textView, the visibility of a view inside the layout, and the value of any of the views inside the layout, like int, bool, float, images, progress bars.
you can however change the view entirely, as in change to another layout.xml
you'll have to be creative to be able to find a way for your widget to change. i think the setViewVisibility() method could help. if you layout every piece that you need and selectively set their visibility based on the state of your widget.
here is a kinda related topic
http://stackoverflow.com/questions/...-dynamically-in-an-android-widget-api-level-3

Hmm, so if I would do 60 linearlayouts and place them next to each other, and say the clock is 13:30, I set the first 30 layouts visible? How would that many views affect performance???

Not sure. Probably wouldn't be good with that many.
This is where you'll have to be creative. Might be good to have one image view and have a bunch of images of the bar at different stages. Though that would require alot of images.
Just remember you can change the content of a view but you cant add another view "on the fly". Its a tricky thing to deal with in an appwidget. Ive been trying to make a widget that displays a tag cloud of your gmail inbox and ive had to use a textView as a wrapper to display the generated html for the cloud instead of adding new textViews for each tag.
From something awesome

Related

Android Expert Required

I want to develop an app that puts a white line grid on a black background.
The grid has 3 columns and 3 rows
There is a 10% border around the grid.
The first column takes up 50% width
The second column takes up 20% width
And the third column takes 10%width
None of the columns expand or contract, they always stay the same size.
Each row is the same height.
If you click any cell, a keyboard appears on the screen allowing you to input data into the cell.
Is it possible to do this white line grid in Android?
If yes, how does one do it?
Best regards
RedTopBox.com
anyone know
Hi All
i have not received any replies.
Can anyone help please
I think it is possible. Do you have a fixed number of rows? is it small? if yes, you could directly use LinearLayout with orientation set to horizontal for each row. There you have android:layout_weight which you can use to play with the different widths you have. For the table borders, just add a View, with a background color of your preference, again use layout_weight if necessary.
If you have too many rows, or you would prefer another approach, you could use TableLayout, and for each row a TableRow, and in the same way use layout_weight for the width. For drawing the borders you could do it in this way: http://www.droidnova.com/display-borders-in-tablelayout,112.html
TableLayout has different parameters like shrinkColumns, or stretchColumns, which you will probably would need, but I am no expert on this, so you would need to play with them.
For displaying a keyboard when the user press on each element of the table, you could have a editText on each, so this would be automatically.
BTW I recommend you asking this type of questions in stackoverflow.com, and tag it with android, there should be more capable people than me to help you with this particular case.

[Q] Live Wallpaper Backgroud

I am pretty new into android development and have a couple questions I'm sure you guys can answer pretty quickly but have so far not been able to figure out. How do I have a set background in a live wallpaper besides just creating something from canvas, I have it already loaded in the hdpi I just need to figure out how to call it. Also, is it possible to have something appear enlarge a little bit in the center of the screen then fall off the screen? I'm trying to create a time lapse of a tree where it goes through all the weather changes. Any sites you could link me too or answers you would have would be greatly appreciated. Thanks for anything you guys are able to do.
Can you be more specific? When you say background are you talking about an image file you've added as a drawable?
If you use the drawBitmap method you can draw images anywhere on a canvas.
This is roughly how I do it on my Live Wallpapers.
Code:
Bitmap background = BitmapFactory.decodeResource(getResources(), R.drawable.background);
c.drawBitmap(background, 0, 0, null);
That will draw the bitmap at the upper left most position on your canvas.
If you want your live wallpaper to slide left and right as you swipe between home screens you need to adjust the x position based on the offset. Look at the cube live wallpaper source code for more information on how to get the offset value.
What I have is a picture loaded in the hdpi file that I want to use as my background, the thing with the cube is it shows you how to draw a picture but not add one into it. I want to load in the photo and then have objects enlarge and drop down around the center of this picture. The design I'm going for is a time lapse of a tree. I was told surfaceView can set your background but I'm not sure if that's the case or not. Thanks for the reply though I appreciate it.
bearcatext said:
the thing with the cube is it shows you how to draw a picture but not add one into it.
Click to expand...
Click to collapse
It works exactly the same but instead of using c.drawLine() you use c.drawBitmap()
That makes a lot of sense thanks, and for the leaves falling would you just set the coordinates to somewhere in the middle then? Also, is there a way to have an image change color mid-screen so it looks like fall is hitting? Thanks for all your help again though.

windowIsFloating=true & window size

I'm developing an activity with a floating main window (e.g. windowIsFloating=true in the activity style). Unfortunately, within a floating window my layout (using fill_parent) is not expanded to the full screen size; fill_parent behaves like wrap_content instead. I suppose floating windows are not automatically sized to the regular/maximized window size.
To circumvent this problem, I use the following code to add the layout to my window:
View view = getLayoutInflater().inflate(R.layout.main, null);
setContentView(view, new LayoutParams(width, height));
This renders my layout correctly. However, how do I find out the correct width and height, taking into account decorations like the status bar? According to the documentation, floating windows automatically get the FLAG_LAYOUT_INSET_DECOR set, causing the WindowManager to report inset rectangle needed to ensure the content is not covered by screen decorations. However, I can't find any documentation on how I can retrieve this inset rectangle; does anyone know this?
I've tried many options (all called from my Activity onCreate method), but they all either return non-usefull information or the full screen size, not taking into account the status bar height:
WindowManager.LayoutParams lp = (WindowManager.LayoutParams)getWindow().getAttributes();
Rect rect = getWindow().getDecorView().getBackground().getBounds();
getWindow().getDecorView().getGlobalVisibleRect(rect);
getWindow().getDecorView().getHitRect(rect);
getWindow().getDecorView().getLocalVisibleRect(rect);
getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
I'm now using a work-around that simply substracts 38 from the height to account for the status bar, but of course that's not a real solution.
Also, does anyone know whether it is possible to hide or overlay the status bar when using a floating window? Setting windowFullScreen=false only works correctly for non-floating windows.
I believe you can set the theme in xml to remove the status bar in your app.
<activity android:name=".YourClassName" android:theme="@android:style/Theme.NoTitleBar"/>
And
<activity android:name=".YourClassName" android:theme="@android:style/Theme.NoTitleBar.Fullscreen"/>
From something awesome
O yea that is in the AndroidManifest.xml
From something awesome

How to Optimize Your Flash SWF Files

Flash files are used widely, but when people use it, they always need new demand. People always chase perfect. SWF files optimization is one of the chasing things. Here is the tip for how to optimaiz flash swf files.
General optimization
Please use symbols, animated or otherwise, for every element that appears more than once. You need to use tweened animations when you are creating animation sequences, because these animations occupy less file space than keyframs. Use movie clips instead of graphic symbols for animations sequences. You need to reduce the area of change in each keyframe as possible as you can to make the action happen in as small area as possible. Try your best to avoid animating bitmap elements and use bitmap images as background or static elements.
Colors
You can use Color menu in the Symbol Property inspector to create many instances of a single symbol in different colors. Then you need to use Color Mixer to match the color palette of the document to a browser-specific palette. Use gradients sparingly. You need about 50 bytes for filling an area with gradient color. You can use alpha transparency sparingly because it can slow playback.
Texts and fonts
You need limit the number of fonts and font style. Please use embedded fonts sparingly because they can increase file size. Select only the needed characters instead of including the entire font for Embed Fonts options.
Lines and elements
Do your best to group elements. You can separate elements that minimize the number of separate lines that are used to describe shapes by using layers. Reduce the number of special line types as possible as you can, such as dashed, dotted, ragged. Solid lines require less memory and lines that are created with the Pencil tool need less memory than brush strokes.
With these tips, you need not to spend extra money to buy some software or tool. What’s more, these tips are easy to understand, you are not required much flash knowledge.

Ball game - chaning ball position

I am making simple ball game and l have problem.I can't change position of Ball. I tried:
1. SetX() and setY() but lower APIs aren't supported.
2. Params and margins but when I move it left or right, the whole activity content is moving with it. Up and down moving is working fine. (Activity will have 10 ImageViews)
3. Android animations - Problem is that I can't get coorinates (getLeft(), getTop()) during the animation.
4. Canvas and draw elements - I change position of image with onDraw() and invalidate() functions but when I but backgorund and all other images (as bitmaps) it is very slow.
Can you give to me any ideas or suggestions? Thanks in advance.
Can you post the code? What do you exactly want to be done, there can be many different "ball games". You want to change the position of a bitmap or circle on the screen create x and y variables, draw bitmap or circle using them and if they change, the object will be drawn elsewhere

Categories

Resources