2014-03-14 234 views
2

我試圖用一個滑動面板從鏈接here,我面臨的圖片中顯示的問題: enter image description hereAndroid的滑動面板與滾動型

我的想法是有自定義內容,當用戶刷卡底部的菜單,並有可能滾動此內容。但是當面板進入錨定狀態時,似乎內容高度設置不正確,因爲某些內容不會顯示。

我在上面的鏈接中下載了示例,並且問題已經出現。我做了一個小改動,加入了scrollview

我錯過了什麼嗎?任何幫助將非常感激。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context=".DemoActivity" > 

<com.sothree.slidinguppanel.SlidingUpPanelLayout 
    xmlns:sothree="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/sliding_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:gravity="bottom" 
    sothree:collapsedHeight="68dp" 
    sothree:dragView="@+id/name" 
    sothree:shadowHeight="4dp" > 

    <TextView 
     android:id="@+id/main" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:clickable="true" 
     android:focusable="false" 
     android:focusableInTouchMode="true" 
     android:gravity="center" 
     android:text="Main Content" 
     android:textSize="16sp" /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="#eee" 
     android:clickable="true" 
     android:focusable="false" 
     android:orientation="vertical" > 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="68dp" 
      android:orientation="horizontal" > 

      <TextView 
       android:id="@+id/name" 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_weight="1" 
       android:gravity="center_vertical" 
       android:paddingLeft="10dp" 
       android:textSize="14sp" /> 

      <Button 
       android:id="@+id/follow" 
       android:layout_width="wrap_content" 
       android:layout_height="match_parent" 
       android:gravity="center_vertical|right" 
       android:paddingLeft="10dp" 
       android:paddingRight="10dp" 
       android:textSize="14sp" /> 
     </LinearLayout> 

     <ScrollView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" > 

      <LinearLayout 
       android:id="@+id/slide_view" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:orientation="vertical" > 

       <ImageView 
        android:id="@+id/image" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:background="@drawable/graphic" /> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:text="teste" /> 

       <ImageView 
        android:id="@+id/image" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:background="@drawable/graphic" /> 

       <ImageView 
        android:id="@+id/image" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:background="@drawable/graphic" /> 
      </LinearLayout> 
     </ScrollView> 
    </LinearLayout> 
</com.sothree.slidinguppanel.SlidingUpPanelLayout> 
</RelativeLayout> 

回答

0

發生此問題的原因是滑動視圖已完全測量,然後部分放在屏幕外。當您向上滑動視圖時,其大小不會改變,只是其位置。這意味着ScrollView在錨定時不完全可見。

我想出的解決方案是使用PanelSlideListener事件來隨着滑動視圖位置的變化調整ScrollView的大小。只需給你的ScrollView一個ID「@ + id/scroll_view」,並使用AndroidSlidingUpPanel演示應用程序中以下onCreate()代碼的修改部分。

final float anchorPoint = 0.5f; 
final ScrollView scrollView = (ScrollView) findViewById(R.id.scroll_view); 
final SlidingUpPanelLayout layout = (SlidingUpPanelLayout) findViewById(R.id.sliding_layout); 
layout.setAnchorPoint(anchorPoint); 
layout.setPanelSlideListener(new PanelSlideListener() { 
    @Override 
    public void onPanelSlide(View panel, float slideOffset) { 
     Log.i(TAG, "onPanelSlide, offset " + slideOffset); 
     setActionBarTranslation(layout.getCurrentParalaxOffset()); 
     resizeScrollView(panel, slideOffset); 
    } 

    @Override 
    public void onPanelExpanded(View panel) { 
     Log.i(TAG, "onPanelExpanded"); 
     resizeScrollView(panel, 0.0f); 
    } 

    @Override 
    public void onPanelCollapsed(View panel) { 
     Log.i(TAG, "onPanelCollapsed"); 
    } 

    @Override 
    public void onPanelAnchored(View panel) { 
     Log.i(TAG, "onPanelAnchored"); 
     resizeScrollView(panel, anchorPoint); 
    } 

    private void resizeScrollView(View panel, float slideOffset) { 
     // The scrollViewHeight calculation would need to change based on 
     // what views you have in your sliding panel. The calculation below 
     // works because your layout has 2 child views. 
     // 1) The row with the drag view which is layout.getPanelHeight() high. 
     // 2) The ScrollView. 
     final int scrollViewHeight = 
      (int) ((panel.getHeight() - layout.getPanelHeight()) * (1.0f - slideOffset)); 
     scrollView.setLayoutParams(
      new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, 
              scrollViewHeight)); 
    } 
}); 
+0

那是什麼「面板」和「佈局」 – clocksmith

+0

@clocksmith之間的區別 - 在回調「面板」將是幻燈片視圖。在這種情況下,它是包含正在調整大小的ScrollView的視圖。 「佈局」是SlidingUpPanelLayout(例如com.sothree.slidinguppanel.SlidingUpPanelLayout) – kjones

+0

我想在面板中使用LIstView。它的工作正常,但我無法在面板中滾動列表。請幫助我。 –