i am making a kind of survey app . i want to hide specific views from the user till he clicks a button.
Can anybody tell me what to do ?
i would be grateful if anyone could help me on this.
You can change the status of the views programmatically.
You should use view.setVisibility(View.GONE) if you want to remove the view from the layout, and view.setVisibility(View.INVISIBLE) if you want to hide it.
To put them back , use view.setVisibility(View.VISIBLE).
try using setVisibility(View.GONE) initially
and onClick use setVisibility(View.VISIBLE)
Sometimes when you just hide a view or set the alpha to 0 it can still be clicked on or touched. Best thing to do is probably to move it on and offscreen. Moving it offscreen:
yourLayoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
yourLayoutParams.leftMargin = (int) screenWidth;
yourLayoutParams.topMargin = (int) screenHeight;
yourView.setLayoutParams(yourLayoutParams);
Related
In my MotionScene I have transition which lasts for several seconds. In ConstraintSet I have a view that is invisible that I want to make visible when the transition is done. But I don't want to animate the view going from Visibility.GONE to Visibility.VISIBLE. Is there a way to stop that?
If needed I can provide code, but it's not that complex. It's just a transition with two ConstraintSet-s, this View is in both sets in starting set it's visibility="visible", and in ending set it's visibility = "gone"
Does anybody have any suggestions?
EDIT: I should note that I did put
android:animateLayoutChanges="false" in root layout of the activity that uses this MotionScene.
If i understand your problem, you can use alpha animation like this;
AlphaAnimation animation1 = new AlphaAnimation(1f, 0.3f);
animation1.setDuration(1000);
animation1.setFillAfter(true);
yourView.startAnimation(animation1);
in our app, I'm loading an initial webview. Then in order to allow users to see chat history, I want to add new webviews on top on that initial one. The way I do that now is to have a linear layout wrapping the initial webview; this LinearLayout is called webview_wrapper and is in a ScrollView. Then, using a ScrollViewListener interface, when the user scrolls up past a set coordinate I create a new webview, call it newWebView, and call webview_wrapper.addView(newWebView, 0), the problem I'm having is that I want to do the loading and adding of the webview off the screen, then the user can continue to scroll up. This adding and scrolling happens inside of an onAnimationEnd method of an AnimationListener(while I make the post request for webview).
I feel like I've tried every way like calling scrollTo or scrollBy after adding the view but it's only scrolling partially. What is the best way to do this?
This problem was eventually solved by using a OnGlobalLayoutListener on the containing ScrollView, inside of which I call scrollTo(0, webViewHeight) and removeOnGlobalLayoutListener(this). Right before that, I make the WebView visible, set its height via setLayoutParams(view must be visible first).
Please correct me if I'm wrong but this probably works as seamlessly as it does because of the OnGlobalLayoutListener. When the view is made visible and the height set, and right after we set an OnGlobalLayoutListener which fires the scrollTo() to the exact height of the new view when the scrollView is being laid out, the net result becomes the appearance of the view inflating off screen.
final int newHeight = (int) ((height / 380.0) * webView.getWidth());
// Must set visible before setting layout params
currentOldView.setVisibility(View.VISIBLE);
// Without this line, view will bounce around as it attempts to self set the height based on HTML content
currentOldView.setLayoutParams(new LinearLayout.LayoutParams(webView.getWidth(), newHeight));
// Use viewTreeObserver to wait until scrollView completely laid out before attempting to scroll
ViewTreeObserver observer = scrollView.getViewTreeObserver();
observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
scrollView.scrollTo(0, newHeight); // Because spinner_wrapper still on view, will scroll to an overlap point.
canAddOldChat = true;
currentOldView.startAnimation(fadeInAnim);
if (isLastOldChat) spinner_wrapper.setAlpha(0.0f);
scrollView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
});
I'm new to javaFX. and I have a question about navigation in ListView, instead of using scrolling bar in the listview for moving up and down, I want to have separated Up and Down buttons for it. But I don't know how to do it, I see somethings with ScaleX and ScaleY but honestly they are not very clear to me.
Can someone help me? What parameters of the listview should be changed when the up or down button is click ?
Thank you very much. I'm using javaFX 8.
There are different options.
You can use the scrollTo-Method of the listView. There you could use the index and just call the Method with an incremented or decremented one.
You can get the scrollbar like this
ScrollBar bar = (ScrollBar) yourListView.lookupAll(".scroll-bar");
and call the setValue-Method to move it with the Buttons.
I have a drawview, and I want to put it inside another view. To do this I have the following code:
DrawView drawview = new DrawView(this);
drawview.setLayoutParams(new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT));
views.addView(drawview);
It works fine, but what I want is that clicking a button change the order of the views, that one view(views) will be over another(drawview).
But I want that all time the two views are showed(the views are transparent).
FrameLayout is the only way to place a view over the other. You can find a detailed documentation about FrameLayout here.
A qestion similar have been answered at
How to put up or down a view programatically?
Sorry to all to "duplicate" the question
I'm looking for an easy way for the user to see how many drinks they've had for a BAC calculator.
Picture of the app:
On button press, I would like an image to be added to the screen, directly under the spinner and with left alignment. When I press the button again, I want another image to be added to the screen.
So if I pressed the add beer button, a drawable of a beer would appear below the spinner. If I pressed the add beer button again, I want there to be TWO drawables of beers under the spinner, preferably with them being added from the right.
(Also, having them reach their width limit, wrapping around, and starting again on the left, but below a full line, would be AWESOME)
I can't figure out how to do this. I assume adding a ImageView in code to a relative layout (because it needs to be positioned to the right) would be the best route, but if it's possible in xml I'd be more than happy to use that. Any help?
In the button's click callback, create an ImageView object, set the bottle image, and position it. For example (I'm assuming the names of your elements):
ImageView imageView = new ImageView(this);
imageView.setImageResource(R.drawable.beerbottle);
RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.RelativeLayout01);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT
);
layoutParams.addRule(RelativeLayout.BELOW, R.id.ButtonRecalculate);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
relativeLayout.addView(imageView, layoutParams);
I haven't tested this, mind you, but it should give you a good start. You'll probably need to add other parameters to the ImageView and possibly to the LayoutParams to make it look good, plus tracking how many bottles are displayed, etc.