2017-10-18 99 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);