File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Android and the fly likes how to add a scrollbar to a view Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Android
Bookmark "how to add a scrollbar to a view" Watch "how to add a scrollbar to a view" New topic
Author

how to add a scrollbar to a view

sohaib rahman
Greenhorn

Joined: Jun 01, 2010
Posts: 20
Dear folks,

I am not able to work with the scrolls which I have added in my XML file called choice.xml. This XML file has a set of radio buttons and an exit button. I have written the following code for choice.xml file:


choice.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="700dip" androidrientation="vertical" android:id="@+id/linearLayout">
<TextView android:layout_width="wrap_content" android:textSize="15sp" android:id="@+id/textView1" android:layout_height="wrap_content" android:text="@string/strChoice"></TextView>
<ScrollView android:id="@+id/scrollView1" android:layout_height="600dip" android:layout_width="fill_parent">
<RadioGroup android:id="@+id/radioGroup1" android:layout_width="wrap_content" android:layout_height="wrap_content">
<RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/optFiveLetterWord" android:text="@string/strFiveLetterWord"></RadioButton>
<RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/optSixLetterWord" android:text="@string/strSixLetterWord"></RadioButton>
<RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/optSevenLetterWord" android:text="@string/strSevenLetterWord"></RadioButton>
<RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/optEightLetterWord" android:text="@string/strEightLetterWord"></RadioButton>
<RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/optNineLetterWord" android:text="@string/strNineLetterWord"></RadioButton>
<RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/optTenLetterWord" android:text="@string/strTenLetterWord"></RadioButton>
<RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/optTwelveLetterWord" android:text="@string/strTwelveLetterWord"></RadioButton>
</RadioGroup>
</ScrollView>
<RelativeLayout android:layout_marginTop="-50dip" android:gravity="bottom" android:layout_height="wrap_content" android:layout_width="fill_parent">
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/btnExit" android:text="@string/strExit"></Button>
</RelativeLayout>
</LinearLayout>

I have not written any code in Choice.java which is an Activity class and corresponds to choice.xml. When I test the application after installing in the android phone, the scroll is not working. It does not work for portrait as well as the landscape orientation.

I know that I have to write the code in Choice.java but don't know what to write and how to use the ScrollView. Please help.
Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Posts: 629

Actually scrollbar comes in picture only when view is not fits into the screen. Your code is correct to test it add more radio buttons then you will see the scrollbar.


Life is easy because we write the source code.....
sohaib rahman
Greenhorn

Joined: Jun 01, 2010
Posts: 20
Yes Pramod,
The suggestion you had given me is true for portrait orientation, but when the orientation changes to landscape the remaining radio buttons go down and I am not able to scroll. What now?
Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Posts: 629

sohaib in landscape mode also you can see the scrollbar. I can see on my emulator.
sohaib rahman
Greenhorn

Joined: Jun 01, 2010
Posts: 20
here is the screenshot of the view


[Download img.bmp] Download

Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Posts: 629

try to scroll the screen by using mouse wheel or by using keyboard. Here I can see the scrollbars in both mode.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how to add a scrollbar to a view
 
Similar Threads
Layout question.
Layout issue-footer image to the bottom of screen (Landscape & portrai) irrespective of body content
Layouts, bottom position
TabHost repeating tab content
when i change android:orientation to horizontal it shows blank screen