Reputation: 4595
I have a layout that contains several items.
It contains a ScrollView.
Now, I want the ScrollBar to be always visible.
I have tried:
android:fadeScrollbars="false"
android:scrollbarAlwaysDrawVerticalTrack="true"
setVerticalScrollBarEnabled (false)
android:scrollbarFadeDuration="0"
But the ScrollBar does not show, unless I touch the ScrollView (in that case it shows and stays as expected).
Please I need the ScrollBar to be always visible (even if not touched),
so that the user knows that he can scroll that element.
Thanks!!
EDIT EDIT EDIT This is the full XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/mainbackground"
android:orientation="vertical"
android:weightSum="1" >
<LinearLayout
android:id="@+id/selector"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="0.1"
android:orientation="horizontal"
android:weightSum="1" >
<TextView
style="@style/T2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:gravity="center"
android:text="@string/month" />
<TextView
android:id="@+id/byday"
style="@style/T2"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:background="@color/tertiarybackground"
android:gravity="center"
android:text="@string/day"
android:textColor="@color/links" />
</LinearLayout>
<RelativeLayout
android:id="@+id/header"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_below="@+id/selector"
android:layout_weight="0.1"
android:background="@color/mainbackground" >
<RelativeLayout
android:id="@+id/previous"
android:layout_width="48dip"
android:layout_height="48dip"
android:layout_alignParentLeft="true" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@drawable/arrow_left" />
</RelativeLayout>
<TextView
android:id="@+id/title"
style="@style/H2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dip"
android:textColor="#000000" />
<RelativeLayout
android:id="@+id/next"
android:layout_width="48dip"
android:layout_height="48dip"
android:layout_alignParentRight="true" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@drawable/arrow_right" />
</RelativeLayout>
</RelativeLayout>
<LinearLayout
android:id="@+id/daysoftheweek"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_below="@+id/header"
android:layout_weight="0.05"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" >
<TextView
style="@style/T2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/sun" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" >
<TextView
style="@style/T2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/mon" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" >
<TextView
style="@style/T2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/tue" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" >
<TextView
style="@style/T2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/wed" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" >
<TextView
style="@style/T2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/thu" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" >
<TextView
style="@style/T2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/fri" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center" >
<TextView
style="@style/T2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/sat" />
</LinearLayout>
</LinearLayout>
<GridView
android:id="@+id/gridview"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_below="@+id/daysoftheweek"
android:layout_gravity="center_horizontal"
android:layout_weight="0.5"
android:listSelector="@android:color/transparent"
android:numColumns="7"
android:stretchMode="columnWidth" />
<ScrollView
android:id="@+id/scroll"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.25"
android:fadeScrollbars="false"
android:scrollbarAlwaysDrawHorizontalTrack="true"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbarFadeDuration="0" >
<LinearLayout
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:orientation="vertical" >
<Button
android:id="@+id/GOTO"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="GOTO" />
</LinearLayout>
</ScrollView>
</LinearLayout>
This is the relevant java snippet:
rLayout = (LinearLayout) findViewById(R.id.text);
ScrollView sv=(ScrollView)findViewById(R.id.scroll);
sv. setScrollbarFadingEnabled(false);
sv.requestFocus();
if (((LinearLayout) rLayout).getChildCount() > 0) {
((LinearLayout) rLayout).removeAllViews();
}
desc = new ArrayList<String>();
date = new ArrayList<String>();
((CalendarAdapter) parent.getAdapter()).setSelected(v);
selectedGridDate = CalendarAdapter.dayString.get(position);
String[] separatedTime = selectedGridDate.split("-");
String gridvalueString = separatedTime[2].replaceFirst("^0*",
"");// taking last part of date. ie; 2 from 2012-12-02.
int gridvalue = Integer.parseInt(gridvalueString);
// navigate to next or previous month on clicking offdays.
if ((gridvalue > 10) && (position < 8)) {
setPreviousMonth();
refreshCalendar();
} else if ((gridvalue < 7) && (position > 28)) {
setNextMonth();
refreshCalendar();
}
((CalendarAdapter) parent.getAdapter()).setSelected(v);
selectedevents.clear();
for (int i = 0; i < Utility.startDates.size(); i++) {
if (Utility.startDates.get(i).equals(selectedGridDate)) {
desc.add(Utility.nameOfEvent.get(i));
}
if (sdf.format(events.get(i).dtstart).equalsIgnoreCase(
selectedGridDate)) {
selectedevents.add(events.get(i));
}
}
if (desc.size() > 0) {
for (int i = 0; i < selectedevents.size(); i++) {
LayoutInflater li = LayoutInflater.from(CalendarView.this);
View row = li.inflate(R.layout.event_row, null);
TextView eventname=(TextView)row.findViewById(R.id.eventname);
TextView eventtype=(TextView)row.findViewById(R.id.eventtype);
eventname.setText(selectedevents.get(i).title);
rLayout.addView(row);
}
Upvotes: 0
Views: 382
Reputation: 12743
put below code in java file:
ScrollView.setScrollbarFadingEnabled(false);
and if stil not show scrollbar then put put below code in xml file:
android:scrollbarFadeDuration="0"
Upvotes: 1