I have made an android activity in that i have put a scrollView,Now i want that when i open the activity,It should alreay scrolled up to 20% ,But it should be scrolled down after that,I have tried so many links and refrences for that,But i am failed to do that,Can anyone please help me how can i do it,My xml code is as below for scrollview,I have put image,I want scrollview show already scrolled to some fixed height on startup of activity.
main.xml
<ScrollView
android:id="#+id/scr_profile"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:scrollY="200dp"
android:scrollbars="none" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
......
</ScrollView>
Have you try Runnable?
final ScrollView scroll = (ScrollView) this.findViewById(R.id.scr_profile);
scroll.post(new Runnable() {
#Override
public void run() {
scroll.scrollTo(200, 200);
}
});
this does work for me.
You can do this:
<ScrollView
android:id="#+id/scr_profile"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:scrollY="200dp"
android:scrollbars="none" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/firstname"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<requestFocus /> //i put here. you can put on the view where you want to scroll
</TextView>
......
Related
I have the following main.axml file
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/refresher"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:choiceMode="singleChoice"
android:id="#+id/myListView" />
<RelativeLayout
android:id="#+id/loadingPanel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true" />
</RelativeLayout>
</android.support.v4.widget.SwipeRefreshLayout>
I require the ability to swipe down on my listview to refresh and also I require a "spinning circle loading animated icon" on initial load. However
if the Listview is above the relative layout as shown i do not get the spinning circle on initial load, but do get my Listview/refresh.
But if i change the RelativeLayout to be above the Listview i get the spinning circle on load but my Listview is not shown after?
In my onCreate method on the acitivity.
protected async override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
// Find view components
blogListView = FindViewById<ListView>(Resource.Id.myListView);
listViewRefresher = FindViewById<SwipeRefreshLayout>(Resource.Id.refresher);
loadingPanel = FindViewById<RelativeLayout>(Resource.Id.loadingPanel);
blogListView.Adapter = new FeedAdapter(this, _blogPosts);
//Register events
listViewRefresher.Refresh += HandleRefresh;
blogListView.ItemClick += OnListItemClick;
// Populate views
await PoplulateBlogPostsFromExternalWebUrl();
loadingPanel.Visibility = ViewStates.Gone;
}
According to the android docs SwipeRefreshLayout can only host one child. As a result the second view is always being hidden. To get this to work you will have to wrap the ListView and RelativeLayout in another RelativeLayout. It's also worth noting that the RelativeLayout wrapping the ProgressBar can probably be removed if an id is put on the ProgressBar.
The OP discovered (in the comments above) that this caused the SwipeRefreshLayout to be triggered when the list was scrolled up. To address this you would need to disable the layout when the list view is not at the top.
Sample Code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/refresher"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:id="#+id/loadingContainer"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:choiceMode="singleChoice"
android:id="#+id/myListView" />
<RelativeLayout
android:id="#+id/loadingPanel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true" />
</RelativeLayout>
</RelativeLayout>
</android.support.v4.widget.SwipeRefreshLayout>
I have requirement like play store app where there is view pager with images and videos
and scroll to view details .Unfortunately when user scrolls the scroll is jumpy but if i remove the scrollview the view pager works perfectly fine .
The layout look and feel is something like this
http://cl.ly/MBRB
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:fillViewport="true">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="160dp"
android:background="#drawable/loading_image"
android:gravity="top"
android:orientation="vertical" >
<android.support.v4.view.ViewPager
android:id="#+id/product_image_pager"
android:layout_width="fill_parent"
android:layout_height="match_parent" />
<com.viewpagerindicator.CirclePageIndicator
android:id="#+id/titles"
style="#style/CirclePageIndicator"
android:layout_alignParentBottom="true"
android:padding="10dip"
android:paddingBottom="10dp" />
</RelativeLayout>
<include layout="#layout/app_screen_menu" />
</LinearLayout>
</ScrollView>
Btw i am loading images from server .
Thanks
You are using 2 scrollisteners
A viewpager uses a scrolllistener
A scrollview uses a scrolllistener
These two scrollistener are fighting for the ScrollEvent.
You can solve this by implementing onInterceptTouch. In this method you can decide who wins the fight over the ScrollEvent
Take a look at this protected post regarding a similair issue containing 2 scrollviews
how do I set the HorizontalScrollView to behave in a right-to-left manner?
The default behavior is that the first tab (the default tab) that is shown is from the left side .
i want the tabs to be sorted in reverse,so that the first 'default' tab will be on the right side of the screen.
how do i do that?
I used layout_gravity but it didn't work ..
Here is my layout code , containing the tabhost and the HorizontalScrollView :
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbars="none">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</HorizontalScrollView>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
</TabHost>
One workaround that works:
final HorizontalScrollView view = (HorizontalScrollView) findViewById(R.id.scroller);
view.postDelayed(new Runnable() {
#Override
public void run() {
view.fullScroll(HorizontalScrollView.FOCUS_RIGHT);
}
}, 10);
The idea is that programmatic scrolling needs a delay for it to work.
I'm sure this is too late, but for anyone else out there with a similar question:
horizontalScrollView.post {
horizontalScrollView.fullScroll(View.FOCUS_RIGHT)
}
you should not use delayed version of post. because post will be added to the end of the message queue.
I have the following layout
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/white" >
<LinearLayout
android:id="#+id/answerMainFrame"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"
android:isScrollContainer="true"
android:onClick="toQuestion" >
<ImageView
android:id="#+id/answer_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:contentDescription="#string/question_img_cd" />
<TextView
android:id="#+id/answer"
style="#style/Question" />
</LinearLayout>
Sometimes the ScrollView is too small and won't fill the whole screen but still I want to call the method toQuestion() clicking anywhere on the screen.
I've tried setting android:layout_height="wrap_content" to the LinearLayout and android:onClick="toQuestion" to the ScrollView but same result.
You could try to let the LinearLayout implement the onClick attribute and then set:
android:fillViewport="true"
to the ScrollView.
I had a similar issue, and simply got rid of the scrollview itself. Instead, I directly inserted the TextView itself, with the constraints previously put on the ScrollView. The whole purpose of my ScrollView was to scroll in the TextView, not among several items, so it seemed a more elegant way to do.
Add a (vertical) scrollbar to my textview in activity.hmtl :
<TextView
android:id="#+id/tvInfo"
(...)
android:scrollbars="vertical"
/>
Add this to the onCreate method:
oTV = (TextView) findViewById(R.id.tvInfo);
oTV.setMovementMethod(new ScrollingMovementMethod());
No need to write the scrolling response. I like that.
I found the solution here (thx Juned Mughal) :
http://www.android-examples.com/make-textview-scrollable-in-android-programmatically/
To make the scroll view fill the screen change:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/white" >
to
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#android:color/white" >
and for the click put this in your onCreate method:
((ScrollView) findViewById(R.id.scrollView))
.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
toQuestion();
}
});
I am having a very weird glitch that I cannot get my head around. Any help will be appreciated as this works on a phone running Android 2.3, tablet running 3.1 but not on a phone running Android 2.1.
I am trying to get the LinearLayout defined in the following XML with the ID of "overview_linear_layout".
overview_view.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<include layout="#layout/listing_view" android:layout_width="fill_parent" android:id="#+id/header_view" android:layout_height="wrap_content"></include>
<ScrollView android:id="#+id/scrollView1" android:layout_weight="1" android:layout_width="fill_parent" android:layout_height="wrap_content">
<LinearLayout android:layout_width="fill_parent" android:orientation="vertical" android:layout_height="fill_parent" android:id="#+id/overview_linear_layout">
<TextView android:scrollbars="vertical" android:longClickable="false" android:layout_weight="1" android:clickable="false" android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="#+id/main_description"></TextView>
</LinearLayout>
</ScrollView>
<include layout="#layout/listing_view" android:layout_width="fill_parent" android:id="#+id/footer_view" android:layout_height="wrap_content" android:layout_weight="0.0"></include>
</LinearLayout>
The code I am using to get the view is as follows:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.overview_view);
LinearLayout linearLayout = (LinearLayout)findViewById(R.id.overview_linear_layout);
if(linearLayout!=null) {
System.out.println("Found linear layout");
}
else {
System.out.println("Did not find linear layout");
}
}
I have tried Project->Clean in Eclipse but that does not help either.
if eclipse don't show overview_linear_layout when you type click on the red cross and click create constant overview_linear_layout in R .
change this
LinearLayout linearLayout = (LinearLayout)findViewById(R.id.overview_linear_layout);
to
LinearLayout linearLayout = (LinearLayout)findViewById(R.layout.overview_linear_layout);`