Multi-View Android ScrollView scrollTo Popover not working - android

My app opens up in View A. In View B, I have made a custom popover who's view contains:
LinearLayout
ScrollView
LinearLayout1
LinearLayout2
.
.
.
LinearLayoutN
What I wish to do is From View A, Move Into View B having set the Vertical Scroll position to a specific LinearLayout from the ScrollView within the Popup.
I have the scrollview being assigned in code to a variable and
variable.scrollTo
is NOT working.
I have also tried to put
sView.post(new Runnable() {
#Override
public void run() {
sView.scrollTo(0, myNum);
}
});
within the routine I run to setup View B, Tried it Outside in the OnCreate routine. Nothing seems to be working to scroll the ScrollView.

The
sView.post(new Runnable() {
#Override
public void run() {
sView.scrollTo(0, scrollYPos);
}
});
was EXTREMELY useful, however its placement was even more important. Do to the scrollview being inside of a popover view, the code above actually had to be placed AFTER the code that truly brought that popover onto screen.

Related

TranslateAnimation in Android with adjacent view

I have a view with TransaleAnimation which works very fine. The problem is view has a android:layout_toRightOf="#id/iv_hook" to an ImageView which doesn't animate with view. Is there any way to achieve this?
The ImageView is for show/hide. when the view slides out i want 'Show' image to display.
Try something like this:
// yourImageView is hidden => its visibility is View.GONE
// animate your view with translation => slide out effect
viewToAnimate.animate().translationX(newTranslationX).setDuration(duration).withEndAction(new Runnable() {
#Override
public void run() {
// now, as the animation has just finished, we want to show the image
yourImageView.setVisibility(View.VISIBLE);
}
}).start();

Android - Scrollview start at the bottom

Is there anyway I can make a Scrollview start on bottom? I tried to:
post(new Runnable() {
#Override
public void run() {
fullScroll(ScrollView.FOCUS_DOWN);
}
});
And also setting the android:focusableInTouchMode="true" on the lowest element in the layout.
But I can see it scrolling to the bottom sometimes. The idea is to make it imperceptible to the user.
Thanks a lot.
try with scrollView.fullScroll(View.FOCUS_DOWN)
Try this
scrollView.scrollTo(0, scrollView.getBottom());
Since I was adding Views dynamically, I also had to allow Android to complete the layout on the content view inside the ScrollView. I just added a post at the end of the View's queue, that will run after it has completed its layout. Otherwise, Android was trying to use the old size of the content view, and wasn't scrolling all the way down.
mMessagesLayout.addView(messageLayout);
mMessagesLayout.requestLayout();
mMessagesLayout.post(new Runnable() {
#Override
public void run() {
mScrollView.scrollTo(0, mScrollView.getBottom());
}
});

Animating a TextView appearing on activity creation

I want to show an animation of a TextView appearing when an activity is created. What I want is to show the activity without the TextView and then the TextView appearing (ideally, flying from outside) in its final position without user interaction.
I've tried to use the transition framework from API level 19 by having the TextView with visibility gone in the XML layout and setting it to visible in onCreate() with this code:
ViewGroup layout = (ViewGroup) findViewById(R.id.main_layout);
TransitionManager.beginDelayedTransition(layout, new ChangeBounds());
textView.setVisibility(View.VISIBLE);
This doesn't work. However, if I don't do this in onCreate() but as a response to a button click, it works. I think that the problem is that the layout is not created yet, so when I set the visibility to visible in the onCreate(), the layout is created with the final state and there aren't two scenes for the TransitionManager to work.
I've tried putting the code in onPause() but the result was the same. Any ideas how this should be done?
Try onWindowFocusChanged() like this
#Override
public void onWindowFocusChanged(boolean hasFocus) {
if(hasFocus){
// start your animation here
}
}
You should do this in onResume() after the layout has been created. Initially the visibility would be Invisible and then the view will animate.
try like this:
ViewGroup layout = (ViewGroup) findViewById(R.id.main_layout);
layout.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
TransitionManager.beginDelayedTransition(layout, new ChangeBounds());
textView.setVisibility(View.VISIBLE);
}
});
because your view should be able to animate only after it's creation

How to slide to imageView in ScrollView

I have a layout in which i have two button:
1)back
2)help
and ScollView in which i place two image Views:
1) firstImageVeiw
1) SecondImageVeiw
first image View will be displayed on front and second is placed beneath the 1st image.
Now i want that if i click on help button the the scrollView automatically slides to 2nd image view.
Any help or suggestion.
You can use scrollview's scrollTo() method
helpbutton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
yourscrollview.scrollTo(0, yourImageView.getTop());
}
});
At runtime you can get the location of every view object with
getleft()
getTop()
getRight()
getBottom()

webview is forcing my scrollview to the bottom

I have a webview in a scrollview, when the Activity loads, it forces my scrollview to the bottom (where the webview is) once the webview finishes "loadData".
How do I keep this from happening?
I've tried this, but it jumps the screen up and down, which I don't want:
ScrollView scroll = (ScrollView)findViewById(R.id.detailsScroll);
scroll.post(new Runnable()
{
#Override
public void run()
{
ScrollView scroll = (ScrollView)findViewById(R.id.detailsScroll);
scroll.fullScroll(ScrollView.FOCUS_UP);
}
});
The answer of fhucho is OK for stoping the webview from scrolling to bottom. But you will lose all accessibility with trackball, etc. So I found an improvement :
public class MyScrollView extends ScrollView {
#Override
public void requestChildFocus(View child, View focused) {
if (focused instanceof WebView )
return;
super.requestChildFocus(child, focused);
}
}
Hope it helps !
Create a custom ScrollView with this method:
#Override
public void requestChildFocus(View child, View focused) {
if (child instanceof WebView) return;
}
For focus related issues, I found this worked better, adding these to your WebView in XML:
android:focusable="false"
android:focusableInTouchMode="false"
Although for the actual question asked, just adding another view that gets the focus by default, instead of the WebView, should have resolved that issue. I think others like me might find this when trying to deal with other general issues with a WebView inside a ScrollView taking the focus. Adding the above to the XML does not stop hyperlinks in the WebView from working.
add this to your main layout
android:descendantFocusability="blocksDescendants"

Categories

Resources