Reputation: 1
<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" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Choose Details"
android:id="@+id/textView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Year"
android:id="@+id/textView2"
android:layout_below="@+id/textView"
android:layout_alignParentLeft="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Branch"
android:id="@+id/textView3"
android:layout_below="@+id/textView2"
android:layout_alignParentLeft="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Semester"
android:id="@+id/textView4"
android:layout_below="@+id/textView3"
android:layout_alignParentLeft="true"/>
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/scrollView"
android:layout_alignTop="@+id/textView2"
android:layout_alignParentRight="true"/>
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/scrollView2"
android:layout_alignTop="@+id/textView4"
android:layout_alignParentRight="true"/>
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/scrollView3"
android:layout_below="@+id/textView4"
android:layout_alignRight="@+id/scrollView2"/>
</RelativeLayout>
I am bit new to android.Could anyone tel me that why arent the three scroll bars visible along the text views.I want to display the scrolls adjacent to their respective textviews.Moreover is the relative layout the best way to align the widgets .
Upvotes: 0
Views: 965
Reputation: 16164
1) Use LinearLayout
instead of RelativeLayout
, set android:orientation="vertical"
2) Put the textview inside your scrollview, like this:
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
...
</TextView>
</ScrollView>
If you put all textviews inside a single scrollview, you will have one scrollbar(Note however that scrollview can only contain one child view, so you'll need to wrap those textviews under a linear layout); if you put one text view in each scrollview and stack those scrollviews vertically in linear layout, then you'll have separate scrollbar for each textview.
Upvotes: 0
Reputation: 5258
The ScrollView
in your layout is not visible because your it does not contain any widget with height
and width
. If you want to see your ScrollView
then you have to set some value to the width
and height
(for example android:layout_width="40dip"
) properties, and a backgroundColor()
, after this you will able to see you ScrollView
.
Upvotes: 0
Reputation: 7636
Until and unless, you add View
element in ScrollView
, the ScrollView
s which u have added cannot be visible, but they are present in layout
. ScrollView
must contain a single View
item either it is a LinearLayout
, RelativeLayout
with child views such as TextView
, ImageView
, EditText
, Button
as below:
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/scrollView2"
android:layout_alignTop="@+id/textView4"
android:layout_alignParentRight="true">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="@+id/image1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" />
</LinearLayout>
</ScrollView>
or a View
element as a single child for ScrollView
as below:
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/scrollView2"
android:layout_alignTop="@+id/textView4"
android:layout_alignParentRight="true">
<ImageView
android:id="@+id/image1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"/>
</LinearLayout>
</ScrollView>
Upvotes: 1
Reputation: 1017
A scroll view is not a scroll bar.
It must contain some elements.
Example :
<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" />
</LinearLayout>
</ScrollView>
Your code should be
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Choose Details"
android:id="@+id/textView"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Year"
android:id="@+id/textView2"
android:layout_below="@+id/textView"
android:layout_alignParentLeft="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Branch"
android:id="@+id/textView3"
android:layout_below="@+id/textView2"
android:layout_alignParentLeft="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Semester"
android:id="@+id/textView4"
android:layout_below="@+id/textView3"
android:layout_alignParentLeft="true"/>
<ScrollView/>
Upvotes: 0