2017-10-18 129 views
0

我只在滚动视图中包含一个直接的孩子,并且我在java文件中添加了下面的代码。当我删除列表视图显示充分的实用方法,但不工作的滚动型滚动视图与列表视图不工作

 ScrollView sv_fragment_globe; 
     sv_fragment_globe = (ScrollView)rowView.findViewById(R.id.sv_fragment_globe); 
     sv_fragment_globe.smoothScrollTo(0,0); 
     Utility.setListViewHeightBasedOnChildren(holder.lv_globe); 

<ScrollView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:id="@+id/sv_fragment_globe" 
     android:fillViewport="true" 
     > 

     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="0dp" 
      android:orientation="vertical" 
      > 

      <ImageView 
       android:layout_width="fill_parent" 
       android:layout_height="200dp" 
       android:src="@drawable/home_hospital1" 
       android:id="@+id/iv_vp_globe" 
       android:scaleType="fitXY" 
       /> 


      <ListView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/lv_globe" 
       > 


      </ListView> 

    </LinearLayout> 

</ScrollView> 



</android.support.v4.widget.SwipeRefreshLayout> 
+0

嵌套可滚动视图是一种反模式。你很可能最终会出现滚动问题 –

回答

0

试试这个

<android.support.v4.widget.SwipeRefreshLayout 
    android:id="@+id/swipe_refresh_layout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 
    <ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    > 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:weightSum="1" 
     > 

     <ImageView 
      android:layout_width="match_parent" 
      android:layout_height="200dp" 
      android:src="@android:drawable/home_hospital" 
      android:id="@+id/iv_vp_globe" 
      android:scaleType="fitXY" 
      /> 


     <ListView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/lv_globe" 
      android:layout_weight="1" 
      > 


     </ListView> 
    </LinearLayout> 
    </ScrollView> 
    </android.support.v4.widget.SwipeRefreshLayout> 
+0

它不起作用 –

+0

@VicChew尝试更新的xml –

+0

整个列表视图很好地出来,但滚动视图不起作用 –

0

如果您有内两个以上的滚动视图任何布局,然后父滚动视图将只滚动。按照下面的步骤来允许孩子的滚动元素滚动。

步骤1: 创建自定义ListView。

公共类ExpandableHeightListView延伸的ListView {

boolean expanded = false; 

public ExpandableHeightListView(Context context) 
{ 
    super(context); 
} 

public ExpandableHeightListView(Context context, AttributeSet attrs) 
{ 
    super(context, attrs); 
} 

public ExpandableHeightListView(Context context, AttributeSet attrs,int defStyle) 
{ 
    super(context, attrs, defStyle); 
} 

public boolean isExpanded() 
{ 
    return expanded; 
} 

@Override 
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) 
{ 
    // HACK! TAKE THAT ANDROID! 
    if (isExpanded()) 
    { 
     // Calculate entire height by providing a very large height hint. 
     // But do not use the highest 2 bits of this integer; those are 
     // reserved for the MeasureSpec mode. 
     int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST); 
     super.onMeasure(widthMeasureSpec, expandSpec); 

     ViewGroup.LayoutParams params = getLayoutParams(); 
     params.height = getMeasuredHeight(); 
    } 
    else 
    { 
     super.onMeasure(widthMeasureSpec, heightMeasureSpec); 
    } 
} 

public void setExpanded(boolean expanded) 
{ 
    this.expanded = expanded; 
} 

}

步骤2:添加下面的行初始化列表视图对象之后。

lv_selected_time_zone.setExpanded(true);