2013-03-12 124 views
1

我有一个从服务器获取数据的异步任务填充的列表视图。但是,当列表视图第一次出现时,滚动条出现,然后立即消失。由于我在列表视图上方显示地图,因此我的主要活动扩展了MapActivity。有谁知道为什么滚动条消失,以及如何纠正?以下是我的主要布局。Listview滚动条消失

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
> 

<TextView 
    android:text="Address is: " 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/address_view" /> 

<com.google.android.maps.MapView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/mapvw" 
    android:layout_width="match_parent" 
    android:layout_height="250dp" 
    android:enabled="true" 
    android:clickable="true" 
    android:apiKey="xxxxxxxxxxxxxxxxxx" 
    /> 
<ListView 
    android:id="@+id/list" 
    android:layout_width="match_parent" 
    android:layout_height="200dp" 
    android:scrollbars="vertical" 
    android:drawSelectorOnTop="false" /> 

</LinearLayout> 

这是我的自定义布局视图。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/linearLayout1" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" > 


    <TextView 
    android:id="@+id/viewtext" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:gravity="center_vertical" 
    android:minHeight="?android:attr/listPreferredItemHeight" 
    android:paddingLeft="6sp" 
    android:textColor="#000000" 
    android:textSize="15sp" 
    android:paddingRight="10sp" 
    /> 
    </LinearLayout> 

而且下面是创建列表视图的逻辑:

@Override 
    protected void onPostExecute(ArrayList<String> result) { 
......... some code 

List<String> viewline = new ArrayList<String>(); 
    ..... some code 
    mapView.postInvalidate(); 

     final ArrayAdapter<String> arrayAdpt = new ArrayAdapter<String>(getApplicationContext(), R.layout.listview, R.id.viewtext, viewline); 

     ListView restaurant_list = (ListView) findViewById(R.id.list); 
     restaurant_list.setChoiceMode(ListView.CHOICE_MODE_SINGLE); 
     restaurant_list.setAdapter(arrayAdpt); 
     restaurant_list.setScrollContainer(true); 
     restaurant_list.setOnItemClickListener(new OnItemClickListener() { 

      @Override 
      public void onItemClick(AdapterView<?> arg0, View arg1, 
        int arg2, long arg3) { 
       // TODO Auto-generated method stub 
       Toast.makeText(getApplicationContext(), "You have selected " + String.valueOf(arg2) + " arg3=" + String.valueOf(arg3) , Toast.LENGTH_LONG).show(); 
      } 

     }); 

    } 

回答

3

有两种方法可以从您的ListView褪色停止你的滚动条。你只需要做其中的一个。

在代码:

restaurant_list.setScrollbarFadingEnabled(false); 

中的XML:

android:fadeScrollbars="false" 

Reference

+0

感谢您的建议。我添加了android:fadeScrollbars =“false”,现在它们出现,但它们不起作用。我正在模拟器上测试,如果我使用鼠标滚轮或者pagedown键没有任何反应。有没有使用模拟器滚动的方法? – Dave 2013-03-12 19:58:28

+0

如果它是触摸屏,请点击并将其向上拖动。 – MCeley 2013-03-12 20:00:44

+0

我尝试点击并拖动,但也没有工作。还有其他建议吗?我现在无法在真正的设备上进行测试,因为我正在等待购买新的Samsung Galaxy。 – Dave 2013-03-12 20:12:25