Hello Friends,
On a specific demand I am going to share very simple code for vertical scroll view in android. Hope it will help you-
Thanks,
1)MainActivity.java
package com.example.scrollviewdemo; import android.app.Activity; import android.os.Bundle; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } }
2)activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true" android:src="@drawable/ic_launcher" /> <ScrollView android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_below="@+id/imageView1" > <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" > <Button android:id="@+id/button1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:text="Button" /> <Button android:id="@+id/button2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:text="Button" /> <Button android:id="@+id/button3" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:text="Button" /> <Button android:id="@+id/button4" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:text="Button" /> <Button android:id="@+id/button5" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:text="Button" /> <Button android:id="@+id/button6" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:text="Button" /> <Button android:id="@+id/button7" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:text="Button" /> <Button android:id="@+id/button8" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:text="Button" /> <Button android:id="@+id/button9" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:text="Button" /> <Button android:id="@+id/button10" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:text="Button" /> <Button android:id="@+id/button11" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:text="Button" /> <Button android:id="@+id/button12" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:text="Button" /> <Button android:id="@+id/button13" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:text="Button" /> <Button android:id="@+id/button14" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:text="Button" /> </LinearLayout> </ScrollView> </RelativeLayout>
no iwint to do two scrollview in one activity
ReplyDeleteHi!
DeleteIf you want one scroll-view work in both orientation(horizontal+vertical) then it is very tuff.
Therefore two way only-
1)Divide screen in two part and use separate scroll view for both.
2)Use custom web-view.
can you tech me how?pls.
Deletewill you please tell me exactly what you want? On same page in detail?
DeleteHey manish dear
Deletepackage in.wptrafficanalyzer.listviewwithimagesandtext;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.SimpleAdapter;
public class MainActivity extends Activity {
// Array of strings storing country names
String[] countries = new String[] {
"India",
"Pakistan",
"Sri Lanka",
"China",
"Bangladesh",
"Nepal",
"Afghanistan",
"North Korea",
"South Korea",
"Japan"
};
// Array of integers points to images stored in /res/drawable-ldpi/
int[] flags = new int[]{
R.drawable.india,
R.drawable.pakistan,
R.drawable.srilanka,
R.drawable.china,
R.drawable.bangladesh,
R.drawable.nepal,
R.drawable.afghanistan,
R.drawable.nkorea,
R.drawable.skorea,
R.drawable.japan
};
// Array of strings to store currencies
String[] currency = new String[]{
"Indian Rupee",
"Pakistani Rupee",
"Sri Lankan Rupee",
"Renminbi",
"Bangladeshi Taka",
"Nepalese Rupee",
"Afghani",
"North Korean Won",
"South Korean Won",
"Japanese Yen"
};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Each row in the list stores country name, currency and flag
List> aList = new ArrayList>();
for(int i=0;i<10;i++){
HashMap hm = new HashMap();
hm.put("txt", "Country : " + countries[i]);
hm.put("cur","Currency : " + currency[i]);
hm.put("flag", Integer.toString(flags[i]) );
aList.add(hm);
}
// Keys used in Hashmap
String[] from = { "flag","txt","cur" };
// Ids of views in listview_layout
int[] to = { R.id.flag,R.id.txt,R.id.cur};
// Instantiating an adapter to store each items
// R.layout.listview_layout defines the layout of each item
SimpleAdapter adapter = new SimpleAdapter(getBaseContext(), aList, R.layout.listview_layout, from, to);
// Getting a reference to listview of main.xml layout file
ListView listView = ( ListView ) findViewById(R.id.listview);
// Setting the adapter to the listView
listView.setAdapter(adapter);
}
}
how to put hyperlink/URl in above code so please tell me and replay on my email id amit.potent@gmail.com please.......
can i use scrollview in absolutelayout
ReplyDeleteYes but its scope will be limited...
Deletenice blog yaar....
ReplyDeleteHey how is the scrollTo(x, y)method working? could you please provide me an example?
ReplyDeleteWhat you mean alex? I did not got you, can you explain detail please?
DeleteIf you are looking for horizonatal scroll view you can try my this blog-
http://www.androidhub4you.com/2012/09/horizontal-scroll-view-in-android.html
Thanks,
Hello. Can you add the code for downloading a file in the app and showing its progress
ReplyDeleteSure I will upload soon! Please keep in touch..
Deletevery helpful :)
ReplyDeleteThanks Ravi!
DeleteNice Job
ReplyDeleteThanks Dear and your welcome!
DeleteThis comment has been removed by the author.
ReplyDeletehi
ReplyDeleteInstead of ScrollView i want to use SimpleGesture and onFling() method.
So that based on the velocity or speed of swipe i can scroll the buttons.
Can you tell me how can we do this?
Thanks
Please use swipe gesture then...
DeleteTry this link-
http://www.androidhub4you.com/2012/07/dynamic-swipe-view-demo-in-android.html
Thank You.
ReplyDeleteIf i scroll fastly last contact or last button should be displayed.
How can i do that?
No idea dear..
DeleteHow can we deduct user scrolling fast? If it is possible then only get swipe speed and set condition like if speed>80 then lastPage :)
Something like that dear. I am not sure..
thank u... :)
ReplyDeleteyour welcome dear!
Deletehello sir, can you pls. help me on how to implement fisher-yates shuffling algorithm in android? i want to shuffle a set of questions using fisher-yates algorithm.
ReplyDeletein java here Random method available here for this task. if you want use your own alog please implement it yourself.
DeleteWhat is The Java Code For Scroll View.....? I want to scroll my Text Which is Long Enough. and I putted it below image View. Now If i want to scoll My Text Then what i should do ? And If i m takin only Text View then Text Is Not Coming Whol....
ReplyDeleteJust put your textview inside scrollview below of your imageview-
DeleteHi Manish,
ReplyDeleteReally helpful for beginners ...can you please help in creating an app which has scroll view nd when we select an item in scroll it will go to its information texts...
using vertical orientation n divide screen in three parts , i have just scroll second part ,what can i do ?? i m a beginner ...
ReplyDeletehow i write text in scroll view
ReplyDeleteUse Edit-text instead of Button.
Deletevery good work mate!
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteI try your code without Imageview but a message " This ScrollView layout or its RelativeLayout parent is useless" appear in xml file. And when i run the code it will suddenly stop...please tell me why?..i 'm beginner...thanks
ReplyDeleteDid you declared your project in manifest file? please check or share your error log cat..
DeleteHi, I have a scroll view with 1000 views in it, and it takes time to display on the screen. any suggestions for this issue?
ReplyDeleteI have two layout exactly same with little bit difference in one layout scrollview is scrolling and in another it is not. Please help me.
ReplyDeleteIn above scroll is working and in below the scroll is not working.
i need to get autoscroll in my application. can i get some help ?
ReplyDeletethanks in advance..
i think you can use thread or check if android have any auto scroll method.
Deletei wnat detail view and text view in one relative lay out plzz tel me urgent
ReplyDeleteHi Manish,
ReplyDeletecan you help me create vertical scroll on Android devices /similar to instagram/ ?
Pls, send email to my @ web24 AT tlen.pl
THX