Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to add a scrollbar to a view

 
sohaib rahman
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 632
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
sohaib rahman
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 632
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sohaib in landscape mode also you can see the scrollbar. I can see on my emulator.
 
sohaib rahman
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here is the screenshot of the view
Filename: img.bmp
Description:
File size: 231 Kbytes
[Download img.bmp] Download Attachment
 
Pramod P Deore
Ranch Hand
Posts: 632
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try to scroll the screen by using mouse wheel or by using keyboard. Here I can see the scrollbars in both mode.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic