By default, the max size of all children is used as the VeiwAnimator's layout size.
How to create ViewAnimator, which height changes depending on the size of displaying child?
Either by specifying the android:measureAllChildren="false" as a ViewAnimator XML attribute or viewAnimator.setMeasureAllChildren(false) in code.
Related
I'm trying to set a height limit to a spinner with a dropdown and an autocompletetextview with a dropdown but I'm running into problems. The only option I see to limit dropdown height is "dropDownHeight" in the AutoCompleteTextView xml. That only lets me set an explicit dropDown height, which is not useful because I need a dropDown height that is relative the amount of items inside it(up to a height limit) The spinner does not even have such an option. thanks in advance
Besides setting an explicit value, as the official doc says:
Specifies the basic height of the dropdown. Its value may be a dimension (such as "12dip") for a constant height, fill_parent or match_parent to fill the height of the screen, or wrap_content to match the height of the content of the drop down.
So the dropDownHeight could meet your requriments.
I am developing an android app. There are six main long variables that are displayed on-screen at any time. These are continually incremented using a timer on a separate thread. The user can watch these variables increase on screen. Each of these variables has a maximum amount.
What I'd like to do is draw a 'progress bar' for each of these variables. At the moment, I am using a View with a solid red colour.
Please see below for prototype:
The red bar on the left would represent a variable that has reached it's maximum amount, whilst the others are empty and the bar has a width of 0, so is invisible. Each variable is placed in a RelativeLayout (which represents one 'section'), which is then placed in a LinearLayout. At a future point I may need to add/remove some - so the solution needs to not rely on hard-coded layout positionings.
My question is how can I programmaticaly set the width of these 'progress bar's in code, whilst not hard-coding the layout co-ordinates of any of the variables?
You should check http://developer.android.com/reference/android/widget/ProgressBar.html ProgressBar. It will ease you with displaying the progress.
In the case of LinearLayout (and any ViewGroup for that matter) you can generate your own LayoutParams programatically:
LayoutParams params = new LayoutParams(width,height) // in px
yourLinearLayout.setLayoutParams(params);
you will need to cast the LayoutParams to the according ViewGroup type.
The regular way would be to use the ProgressBar, but if you want to use your custom view, use this:
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(withInPx, heightInPx);
yourView.setLayoutParams(lp);
This assumes you use LinearLayout, but you should edit that if you use a different layout (i.e. RelativeLayout)
The heightInPx will be fixed in your case, but the withInPx you can vary, according to the progress.
I have a TabLayoutPanel and i don't want to give it a fixed height like in the following code example (tabPanel.setHeight("100px");). I want to give it the height of the tab content e.g. the HTML-Widget in the first tab). If i don't set the hight manually, the tab content is not shown at all. Is there any way to get this working with a height adapted to the content?
public class GWTTest implements EntryPoint {
public void onModuleLoad() {
TabLayoutPanel tabPanel = new TabLayoutPanel(3, Unit.EM);
tabPanel.setAnimationDuration(400);
tabPanel.add(new HTML("Tab1 Content"), "Tab 1");
tabPanel.add(new HTML("Tab2 Content"), "Tab 2");
tabPanel.setHeight("100px");
RootPanel.get().add(tabPanel);
}
}
I also tried to mess around directly in the css with the "overflow" and "postition"-attributes, but this then breaks always the animation or something else.
Edit: It seems the easiest way would be to implement my own tab panel - or use an existing javascript library.
Layout panels are a special kind of container in GWT that required sizes from their parents and can size themselves. The basis is the two interfaces ProvidesResize and RequiresResize - indicates that the object will size its children, the other that it must be sized when the parent's size changes. Most layout panels (like TabLayoutPanel) implements both - it needs a size change from its parent, and when it gets it, it will size its children, each tab.
To kick it off though, you need to add the root widget to a RootLayoutPanel, not a RootPanel. There are several chief differences - there is only one RootLayoutPanel (no get(String) method), and the RootLayoutPanel will size its children, while RootPanel will not.
Use RootLayoutPanel.get().add(tabPanel) instead of RootPanel.get().add(tabPanel).
I have also ran up with this issue, but sadly it requires height to be set. All the workaround s where a failure. But some of them suggest the following.
You can try to replace the TabLayoutPanel with a HeaderPanel:
A panel that includes a header (top), footer (bottom), and content
(middle) area. The header and footer areas resize naturally. The
content area is allocated all of the remaining space between the
header and footer area.
Alternatively you can override the onResize() method your ResizeLayoutPanel calculate the height of your embedded content and set the appropriate height.
If you want scrolling functionality you have to embed your VerticalPanel in a ScrollPanel or use CSS to set the oferflow property.
When I use include in a layout, I have to set width and height both to include tag and to the layout it is linked to. Otherwards it won't work correctly. So, it seems, that include is not a link, but a subclass of View, if it has its own width, height, id and so on. But on developer's site there is not such class as include. Who are you, Mr. include?
The <include> tag can be thought of as a copy/paste of the internal layout. It's part of the xml parsing that's in the View Inflater classes. It effectively takes the layout ID, inflates the xml object you pass in, then adds it to the main layout that it's inflating based on the attributes of the included layout. You can use it on anything that inherits from View.
You can overwrite any of the attributes that have layout_ in them. You don't have to overwrite the width and height attributes if they are included in the root of the layout your including. However, you do have to overwrite those parameters if you are overwriting any other attribute. It's part of a bug in how <include> is parsed. If you want to change, say, layout_marginLeft, you would have to overwrite layout_width and layout_height to the same values that are in the layout in order for the parser to overwrite the left margin attribute.
include doesn't actually need a width and height if you specify the width and height of the root element of the included layout. In other words, this is entirely valid:
<include layout="#layout/my_included_layout" />
So long as my_included_layout has a root element with a width and height it will be happy.
Please advice how to set fixed heigh (in dip) for the child view of ListView component?
I am using relative layout as root layout for the child view
when I set backgoround image to relative layout it becomes very height (maybe because backgoround picture is large) and I want to set precisely the height in dp.
Stumbled on this problem while looking for an answer to a somewhat related question.
Anyway, the problem is with inflating the view. In your getView (or newView if you're using CursorAdapter), when inflating a new layout, instead of doing
inflater.inflate(R.layout.your_layout, null)
do this instead:
inflater.inflate(R.layout.your_layout, parent, false)
Passing the parent view will make the child honor it's parents bounds, and false means you're instructing the inflater to NOT attach it to the parent. Setting a fixed height in dip will work after you do this.
For specifying the child height in dip via java code see following discussions:
1. setWidth in dip
2. how to specify padding in dip
3. Correct way to specify dimensions in Java code