除非我触摸ScrollView,否则我的ScrollView中的ScrollBars不会显示

时间:2013-10-15 12:03:30

标签: android

我的布局包含多个项目。

它包含一个ScrollView。

现在,我希望ScrollBar始终可见。

我试过了:

android:fadeScrollbars="false"

android:scrollbarAlwaysDrawVerticalTrack="true"

setVerticalScrollBarEnabled (false)

android:scrollbarFadeDuration="0"

但ScrollBar没有显示,除非我触摸ScrollView(在这种情况下它显示并保持预期)。

我需要ScrollBar始终可见(即使没有触及),

以便用户知道他可以滚动该元素。

谢谢!


编辑编辑 这是完整的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>

这是相关的java片段:

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);
                           }

1 个答案:

答案 0 :(得分:1)

将以下代码放在java文件中:

ScrollView.setScrollbarFadingEnabled(false);

如果仍然没有显示滚动条然后放 将下面的代码放在xml文件中:

android:scrollbarFadeDuration="0"