在Layout + Viewpager + listview中添加Scrollview有可能吗?

时间:2016-06-18 06:28:06

标签: android android-viewpager android-recyclerview android-scrollview

  • 我正在尝试添加Layout + View寻呼机+列表视图,Layout + View寻呼机工作正常但在回收器视图中查看寻呼机不滚动。
  • 有可能......引导我 - 感谢

requirement Screenshot

  • 如何动态地将viewpager设置为recyclear视图高度

  • 我的xml代码......

        

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/imageView3"
        android:background="@drawable/profile"
        android:layout_alignParentTop="true"
        android:layout_alignParentStart="true"
        android:layout_marginTop="27dp" />
    
    
    
    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        app:tabMode="fixed"
        app:tabGravity="fill"
        app:tabTextColor="@color/your_unselected_text_color"
        app:tabSelectedTextColor="@color/your_selected_text_color"
        android:layout_below="@+id/imageView3"
        android:layout_alignParentStart="true" />
    
    
    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignBottom="@+id/tabs"
        android:layout_alignParentStart="true">
    
    </android.support.v4.view.ViewPager>
    
    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/android.support.v7.widget.RecyclerView"
        android:layout_alignParentBottom="true"
        android:layout_alignParentStart="true">
    
    </android.support.v7.widget.RecyclerView>
    </LinearLayout>
    

1 个答案:

答案 0 :(得分:0)

首先在项目中复制此类文件

import android.content.Context;
import android.util.AttributeSet;
import android.view.ViewGroup;
import android.widget.ListView;

public class ExpandableHeightListView extends 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) {
    if (isExpanded()) {
        // Calculate entire height by providing a very large height hint.
        // View.MEASURED_SIZE_MASK represents the largest height possible.
        int expandSpec = MeasureSpec.makeMeasureSpec(MEASURED_SIZE_MASK,
                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;
}
}

然后在scrollview中使用ExpandableHeightlistview,就像这样

<ScrollView ...>
<RelativeLayout ...>
    <viewpager></viewpager>
    <com.example.ExpandableHeightListView ... />
    <other view items />
</RelativeLayout>

然后是listview的setadpater 最后也是非常重要的listview.setExpandable(true)