2013-10-15 74 views
0

我有一個包含多個項目的佈局。我的ScrollView中的滾動條不會顯示,除非我觸摸ScrollView

它包含一個ScrollView。

現在,我希望ScrollBar始終可見。

我曾嘗試:

android:fadeScrollbars="false"

android:scrollbarAlwaysDrawVerticalTrack="true"

setVerticalScrollBarEnabled (false)

android:scrollbarFadeDuration="0"

但滾動條不顯示,除非我觸摸滾動型(在這種情況下,它顯示並按預期保持)。

請我需要滾動條是始終可見(即使沒有觸及),

,使用戶知道他可以滾動該元素。

謝謝!


編輯編輯編輯 這是一個完整的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); 
          } 
+0

在一個單獨的說明:這些都是很多嵌套佈局的你那裏。您實際上並不需要爲了定位而將'TextView'放入'LinearLayout'中。例如,'id/daysoftheweek'的所有孩子都應該是「TextViews」本身,而不是'LinearLayout'。 –

+0

@Lisa其中是添加新元素到滾動視圖的代碼。 – Riser

+0

@Segi對不起Segi,剛剛編輯 –

回答

1

把下面的代碼的Java文件:

ScrollView.setScrollbarFadingEnabled(false); 

,如果還是老樣子沒有顯示滾動條,然後把 放下面的代碼在XML文件:

android:scrollbarFadeDuration="0" 
+0

不,對不起,不工作... :-( –

+0

你可以告訴我你的xml代碼嗎?@Lisa – Riser

+0

XML貼,謝謝!!! –