Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/198.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 除非触摸ScrollView,否则我的ScrollView中的滚动条不会显示_Android - Fatal编程技术网

Android 除非触摸ScrollView,否则我的ScrollView中的滚动条不会显示

Android 除非触摸ScrollView,否则我的ScrollView中的滚动条不会显示,android,Android,我有一个包含多个项目的布局 它包含一个滚动视图 现在,我希望滚动条始终可见 我试过: android:fadeScrollbars=“false” android:scrollbarAlwaysDrawVerticalTrack=“true” setVerticalScrollBarEnabled(false) android:scrollbarFadeDuration=“0” 但是滚动条不会显示,除非我触摸滚动视图(在这种情况下,它会显示并保持预期状态) 请确保滚动条始终可见(即使未触摸),

我有一个包含多个项目的布局

它包含一个滚动视图

现在,我希望滚动条始终可见

我试过:

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);
                           }
rLayout=(LinearLayout)findviewbyd(R.id.text);
ScrollView sv=(ScrollView)findViewById(R.id.scroll);
sv。SetScrollBarFadinEnabled(假);
sv.requestFocus();
if(((LinearLayout)rLayout.getChildCount()>0){
((线性布局)rLayout).删除所有视图();
}
desc=新的ArrayList();
日期=新的ArrayList();
((CalendarAdapter)parent.getAdapter()).setSelected(v);
selectedGridDate=CalendarAdapter.dayString.get(位置);
String[]separatedTime=selectedgridate.split(“-”);
String gridvalueString=separatedTime[2]。replaceFirst(“^0*”,
"");// 参加约会的最后一部分。ie;2从2012年12月2日开始。
int gridvalue=Integer.parseInt(gridvalueString);
//单击offdays导航到下个月或上个月。
如果((网格值>10)和&(位置<8)){
setPreviousMonth();
刷新日历();
}否则如果((网格值<7)和(&(位置>28)){
setNextMonth();
刷新日历();
}
((CalendarAdapter)parent.getAdapter()).setSelected(v);
selectedevents.clear();
对于(int i=0;i0){
对于(int i=0;i
将以下代码放入java文件中:

ScrollView.setScrollbarFadingEnabled(false);
如果仍然没有显示滚动条,则将 将以下代码放入xml文件中:

android:scrollbarFadeDuration="0"

另一方面:这里有很多嵌套的布局。实际上,你不需要在
线性布局中放置
TextView
来定位。例如,
id/daysoftheweek
的所有孩子都应该是
TextView
本身,而不是
LinearLayout
s.@Lisa哪里是t他编写了在scrollview中添加新元素的代码。?@Segi抱歉,Segi,只是edited@Lisa那么现在…做了什么。?@Segi在代码的末尾看到
rLayout.addView(行);
谢谢!!!@Lisa这是因为你的身高=0dp。只需将身高值设置为40dp。@Segi这是个糟糕的建议。在这里使用0dp是因为体重决定身高。@Lisa没有显示,因为只有一个按钮。只需将6到7个按钮放入其中进行测试。@Segi滚动视图不是空的,我填充了一个按钮t运行时