ScrollView在Android中不起作用

时间:2016-04-27 07:07:33

标签: android scroll scrollview

我有一个包含视图寻呼机,回收站视图等的片段。 我想将所有这些放在滚动视图中,但它只是拒绝滚动。我在这里错过了什么吗? 我已经尝试设置fillViewport false,并删除滚动条:无,以及其他一些东西,但没有任何帮助..

<ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fillViewport="true"
        android:scrollbars="none">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <LinearLayout
                android:id="@+id/headerLayout"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:orientation="horizontal"
                android:gravity="center_vertical">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="abc"/>

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@drawable/image"/>
            </LinearLayout>

            <android.support.v7.widget.RecyclerView
                android:layout_below="@id/headerLayout"
                android:id="@+id/recyclerView"
                android:scrollbars="none"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>


            <android.support.v4.view.ViewPager
                android:layout_below="@id/recyclerView"
                android:id="@+id/viewpager"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <android.support.v4.view.PagerTabStrip
                    android:id="@+id/pager_header"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="top"/>
            </android.support.v4.view.ViewPager>
        </RelativeLayout>
    </ScrollView>

1 个答案:

答案 0 :(得分:0)

当我在评论中回复时,请检查 public class FeedRecyclerStickyHeaderAdapter<T> extends RecyclerStickyTypeWrapper<T> implements StickyRecyclerHeadersAdapter<RecyclerView.ViewHolder> { private static final String TAG = FeedRecyclerStickyHeaderAdapter.class.getSimpleName(); public static final int VIEW_LOOK = 0; public static final int VIEW_PRODUCT = 1; public static final int VIEW_BLOG = 2; public static final int VIEW_BRAND = 3; public static final int VIEW_PROGRESS = 4; public static final int VIEW_AD = 5; public static final int VIEW_NEW_ARRIVALS = 6; public static final int VIEW_FEATURED_BRANDS = 7; public static final int VIEW_BIG_BANNER = 8; public static final int VIEW_BRAND_FEED = 9; private static final int TOTAL_VIEWS = 10; private OnInteractionListener listener; private OnButtonClickListener callback; private Fragment fragment; private Handler handler; private TimerTask task; private ArrayList<RecyclerView.ViewHolder> holderArrayList; public FeedRecyclerStickyHeaderAdapter(Activity context, @NonNull List<T> objects, @NonNull OnInteractionListener listener) { super(); this.context = context; this.objects = objects; this.listener = listener; holderArrayList = new ArrayList<>(objects.size()); } public FeedRecyclerStickyHeaderAdapter(Activity context, @NonNull List<T> objects, Fragment fragment, @NonNull OnInteractionListener listener) { super(); this.context = context; this.objects = objects; this.fragment = fragment; this.listener = listener; } /** * Used for feeds for adding products to wishlist * * @param context * @param objects * @param fragment * @param listener * @param callback */ public FeedRecyclerStickyHeaderAdapter(Activity context, @NonNull List<T> objects, Fragment fragment, @NonNull OnInteractionListener listener, @NonNull OnButtonClickListener callback) { super(); this.context = context; this.objects = objects; this.fragment = fragment; this.listener = listener; this.callback = callback; } @Override public int getItemViewType(int position) { if (position > -1 && position < objects.size()) { if (objects.get(position) instanceof Feed) { switch (((Feed) objects.get(position)).getViewType()) { case Feed.LOOK_VIEW: return VIEW_LOOK; case Feed.BLOG_VIEW: return VIEW_BLOG; case Feed.PRODUCT_VIEW: return VIEW_PRODUCT; case Feed.PROGRESS_VIEW: return VIEW_PROGRESS; case Feed.FEATURED_BRANDS_VIEW: return VIEW_FEATURED_BRANDS; case Feed.NEW_ARRIVAL_VIEW: return VIEW_NEW_ARRIVALS; case Feed.AD_VIEW: return VIEW_AD; case Feed.BRAND_VIEW: return VIEW_BRAND; } } else if (objects.get(position) instanceof BrandFeed) { switch (((BrandFeed) objects.get(position)).getViewType()) { case BrandFeed.AD_VIEW: return VIEW_AD; case BrandFeed.BIG_BANNER_VIEW: return VIEW_BIG_BANNER; case BrandFeed.BRAND_FEED_VIEW: return VIEW_BRAND_FEED; case BrandFeed.PROGRESS_VIEW: return VIEW_PROGRESS; } } else if (objects.get(position) instanceof Looks) { if (null != ((Looks) objects.get(position)).getLookId()) return VIEW_LOOK; else return VIEW_PROGRESS; } else if (null == objects.get(position)) return VIEW_PROGRESS; } return super.getItemViewType(position); } @Override public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View v; switch (viewType) { case VIEW_LOOK: { ViewHolderLook holder = new ViewHolderLook(LayoutInflater.from(context) .inflate(R.layout.listitem_look, parent, false)); if (2 <= context.getResources().getInteger(R.integer.gridviewcolumn)) { initializeHeaders(holder.view, holder); } return holder; } case VIEW_PRODUCT: { ViewHolderProduct holder = new ViewHolderProduct(LayoutInflater.from(context) .inflate(R.layout.listitem_new_product, parent, false)); if (2 <= context.getResources().getInteger(R.integer.gridviewcolumn)) { initializeHeaders(holder.view, holder); } return holder; } case VIEW_BLOG: { ViewHolderBlog holder = new ViewHolderBlog(LayoutInflater.from(context) .inflate(R.layout.blog_list_item_new, parent, false)); if (2 <= context.getResources().getInteger(R.integer.gridviewcolumn)) { initializeHeaders(holder.view, holder); } return holder; } case VIEW_BRAND: { ViewHolderBrands holder = new ViewHolderBrands(LayoutInflater.from(context) .inflate(R.layout.listitem_feed_brand, parent, false)); if (2 <= context.getResources().getInteger(R.integer.gridviewcolumn)) { initializeHeaders(holder.view, holder); } return holder; } case VIEW_PROGRESS: { v = LayoutInflater.from(context).inflate(R.layout.dialog_progress, parent, false); return new ViewHolderProgress(v); } case VIEW_AD: { v = LayoutInflater.from(context).inflate(R.layout.listitem_offers, parent, false); return new ViewHolderAd(v); } case VIEW_NEW_ARRIVALS: { v = LayoutInflater.from(context).inflate(R.layout.listitem_new_arrivals, parent, false); return new ViewHolderNewArrivals(v); } case VIEW_FEATURED_BRANDS: { v = LayoutInflater.from(context).inflate(R.layout.listitem_featured_brands, parent, false); return new ViewHolderFeaturedBrands(v); } case VIEW_BRAND_FEED: { v = LayoutInflater.from(context).inflate(R.layout.listitem_brandfeed, parent, false); return new ViewHolderBrandFeed(v); } case VIEW_BIG_BANNER: { v = LayoutInflater.from(context).inflate(R.layout.listitem_brandfeed_big_banner, parent, false); return new ViewHolderBigBanner(v); } } return null; } @Override public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { if (BuildConfig.DEBUG) Log.d(TAG, "onBindViewHolder: " + position); if (null != holder) { if (holder instanceof ViewHolderLook) { if (2 <= context.getResources().getInteger(R.integer.gridviewcolumn)) { setHeadersData((ViewHolderLook<T>) holder, position); } bindLookView((ViewHolderLook<T>) holder, position); } else if (holder instanceof ViewHolderProduct) { if (2 <= context.getResources().getInteger(R.integer.gridviewcolumn)) { setHeadersData((ViewHolderProduct<T>) holder, position); } bindProductView((ViewHolderProduct<T>) holder, position); } else if (holder instanceof ViewHolderBlog) { if (2 <= context.getResources().getInteger(R.integer.gridviewcolumn)) { setHeadersData((ViewHolderBlog<T>) holder, position); } bindBlogView((ViewHolderBlog<T>) holder, position); } else if (holder instanceof ViewHolderBrands) { if (2 <= context.getResources().getInteger(R.integer.gridviewcolumn)) { setHeadersData((ViewHolderBrands<T>) holder, position); } bindBrand((ViewHolderBrands<T>) holder, position); } else if (holder instanceof ViewHolderAd) bindAd((ViewHolderAd<T>) holder, position); else if (holder instanceof ViewHolderNewArrivals) bindNewArrival((ViewHolderNewArrivals<T>) holder, position); else if (holder instanceof ViewHolderFeaturedBrands) bindFeaturedBrands((ViewHolderFeaturedBrands<T>) holder, position); else if (holder instanceof ViewHolderProgress) { if (2 == context.getResources().getInteger(R.integer.gridviewcolumn)) { StaggeredGridLayoutManager.LayoutParams layoutParams = (StaggeredGridLayoutManager.LayoutParams) holder.itemView.getLayoutParams(); layoutParams.setFullSpan(true); holder.itemView.setLayoutParams(layoutParams); } } else if (holder instanceof ViewHolderBigBanner) { bindBigBanner((ViewHolderBigBanner<T>) holder, position); } else if (holder instanceof ViewHolderBrandFeed) { bindBrandFeed((ViewHolderBrandFeed<T>) holder, position); } if (null == holderArrayList) holderArrayList = new ArrayList<>(); if (null != objects && position != -1 && position < objects.size()) { if (position < holderArrayList.size() || position == 0) holderArrayList.add(position, holder); else holderArrayList.add(holder); } } } @Override public long getHeaderId(int position) { if (2 <= context.getResources().getInteger(R.integer.gridviewcolumn)) return -1; switch (getItemViewType(position)) { case VIEW_PROGRESS: case VIEW_AD: case VIEW_NEW_ARRIVALS: case VIEW_FEATURED_BRANDS: case VIEW_BIG_BANNER: case VIEW_BRAND_FEED: return -1; default: return getItem(position).hashCode(); } } @Override public long getItemId(int position) { return getItem(position).hashCode(); } @Override public RecyclerView.ViewHolder onCreateHeaderViewHolder(ViewGroup parent) { StickyHeaderViewHolder<T> holder = new StickyHeaderViewHolder<T>(LayoutInflater.from(context) .inflate(R.layout.listitem_header, parent, false)); initializeHeaders(holder.view, holder); return holder; } @Override public void onBindHeaderViewHolder(RecyclerView.ViewHolder viewHolder, int position) { if (BuildConfig.DEBUG) Log.d(TAG, "onBindHeaderViewHolder: " + position); if (viewHolder instanceof StickyHeaderViewHolder) { setHeadersData((StickyHeaderViewHolder) viewHolder, position); } } /** * Overloading function for setting headers for tabs for sticky headers * * @param holder * @param position */ private void setHeadersData(StickyHeaderViewHolder holder, int position) { holder.view.setOnClickListener(new View.OnClickListener() { // This click listener is not working as sticky headers are just canvas and not views // as desired for click listeners. @Override public void onClick(View v) { if (null != v.getTag()) { if (v.getTag() instanceof Looks) { Looks data = (Looks) v.getTag(); openLook(data); } else if (v.getTag() instanceof Brand) { Brand data = (Brand) v.getTag(); openBrand(data.getBrandId(), data.getBrandName()); } else if (v.getTag() instanceof Product) { Product data = (Product) v.getTag(); openBrand(data.getBrandId(), data.getBrandName()); } else if (v.getTag() instanceof Blog) { Blog data = (Blog) v.getTag(); } } } }); final T type = getItem(position); if (type instanceof Feed) { Feed object = (Feed) type; switch (object.getViewType()) { case Feed.LOOK_VIEW: { Looks data = object.getLook(); holder.imgHeaderDp.setImageUrl(data.getStylistImage(), MyApp.getInstance().getImageLoader()); holder.lblHeaderName.setText(data.getStylistName()); holder.lblHeaderTime.setText(TimeConversions.longToPrettyTimeString(data.getCreatedDate())); holder.lblHeaderTime.setVisibility(View.VISIBLE); holder.view.setVisibility(View.VISIBLE); holder.view.setTag(data); break; } case Feed.BLOG_VIEW: { Blog data = object.getBlog(); // holder.imgHeaderDp.setImageUrl(data.getThumb(), MyApp.getInstance().getImageLoader()); holder.lblHeaderName.setText(data.getAuthorName()); holder.lblHeaderTime.setText(TimeConversions.longToPrettyTimeString(data.getPostedDate())); // holder.lblHeaderTime.setVisibility(View.VISIBLE); holder.view.setVisibility(View.VISIBLE); holder.view.setTag(data); break; } case Feed.PRODUCT_VIEW: { Product data = object.getProduct(); // holder.imgHeaderDp.setImageUrl(data.getProductThumbnail(), MyApp.getInstance().getImageLoader()); holder.lblHeaderName.setText(data.getBrandName()); holder.lblHeaderTime.setVisibility(View.GONE); holder.view.setVisibility(View.VISIBLE); holder.view.setTag(data); break; } case Feed.BRAND_VIEW: { Brand data = object.getBrand(); holder.imgHeaderDp.setImageUrl(data.getImgLogoUrl(), MyApp.getInstance().getImageLoader()); holder.lblHeaderName.setText(data.getBrandName()); holder.lblHeaderTime.setVisibility(View.GONE); holder.view.setVisibility(View.VISIBLE); holder.view.setTag(data); } } } else if (objects.get(position) instanceof Looks) { if (null != ((Looks) objects.get(position)).getLookId()) { // Looks in Looks feed Looks data = ((Looks) objects.get(position)); holder.imgHeaderDp.setImageUrl(data.getStylistImage(), MyApp.getInstance().getImageLoader()); holder.lblHeaderName.setText(data.getStylistName()); holder.lblHeaderTime.setText(TimeConversions.longToPrettyTimeString(data.getCreatedDate())); holder.lblHeaderTime.setVisibility(View.VISIBLE); holder.view.setVisibility(View.VISIBLE); holder.view.setTag(data); } } } class ViewHolderLook<T> extends RecyclerView.ViewHolder { // Header RoundedNetworkImageView imgHeaderDp; FontTextView lblHeaderName; FontTextView lblHeaderTime; View view; // Body FontTextView lblLookName, lblLookDesc; CustomCheckbox chkFavorite; ImageView btnShare; SquareNetworkImageView imgLook; public ViewHolderLook(View view) { super(view); chkFavorite = (CustomCheckbox) view.findViewById(R.id.chk_favorite); btnShare = (ImageView) view.findViewById(R.id.btn_share); imgLook = (SquareNetworkImageView) view.findViewById(R.id.img_look); lblLookName = (FontTextView) view.findViewById(R.id.lbl_title); lblLookDesc = (FontTextView) view.findViewById(R.id.lbl_desc); // if it's tab then only initialize else not required if (2 <= context.getResources().getInteger(R.integer.gridviewcolumn)) { this.view = view.findViewById(R.id.header); } } } class ViewHolderBlog<T> extends RecyclerView.ViewHolder { // Header RoundedNetworkImageView imgHeaderDp; FontTextView lblHeaderName; FontTextView lblHeaderTime, lblReadFull; View view; View shareView, root; LinearLayout llShare; FontTextView lblBlogTitle, lblAuthor, lblRead, lblTime, lblDescription, lblLookCount; FontButton btnCopyToClipboard, btnWhatsApp, btnEmail, btnFacebook, btnTwitter, btnGPlus, btnPinterest, btnInstagram; SquareNetworkImageView imgBlog; CustomNetworkImageView blog_image; ImageView chkShare; public ViewHolderBlog(View view) { super(view); lblBlogTitle = (FontTextView) view.findViewById(R.id.blog_title); lblDescription = (FontTextView) view.findViewById(R.id.blog_description); lblLookCount = (FontTextView) view.findViewById(R.id.lbl_looks_count); lblAuthor = (FontTextView) view.findViewById(R.id.txt_author); imgBlog = (SquareNetworkImageView) view.findViewById(R.id.iv_blogimage); lblRead = (FontTextView) view.findViewById(R.id.txt_read); lblTime = (FontTextView) view.findViewById(R.id.txt_timer); llShare = (LinearLayout) view.findViewById(R.id.ll_share_container); chkShare = (ImageView) view.findViewById(R.id.share); blog_image = (CustomNetworkImageView) view.findViewById(R.id.blog_image); lblReadFull = (FontTextView) view.findViewById(R.id.read_full); this.root = view; // if it's tab then only initialize else not required if (2 <= context.getResources().getInteger(R.integer.gridviewcolumn)) { this.view = view.findViewById(R.id.header); } } } class ViewHolderAd<T> extends RecyclerView.ViewHolder { protected CustomViewPager viewPager; protected LinearLayout llPage; public ViewHolderAd(View view) { super(view); viewPager = (CustomViewPager) view.findViewById(R.id.view_pager); llPage = (LinearLayout) view.findViewById(R.id.ll_page); } } . . . . } 的适配器类。我不会解释它,因为它太大而无法解释。但对于初学者,请点击链接Recyclerview and handling different type of row inflation

对于以下代码,您可以将其与Google商店

中的StyFi应用相关联
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/lookforu_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.mycompany.myapp.app.custom.widget.GifSwipeRefreshLayout
        android:id="@+id/refresh_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <view
            android:id="@+id/grid_view"
            class="android.support.v7.widget.RecyclerView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/half_padding"
            android:gravity="center" />

    </com.mycompany.myapp.app.custom.widget.GifSwipeRefreshLayout>
</RelativeLayout>

这是第一个Feed屏幕的布局

/*final MenuItem item = menu.findItem(R.id.search);
    final SearchView searchView = (SearchView) MenuItemCompat.getActionView(item);
    searchView.setOnQueryTextListener(this);*/

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
    if (null != searchView)
    {
        searchView.setSearchableInfo(searchManager
                .getSearchableInfo(getComponentName()));
        searchView.setIconifiedByDefault(true);
    }

    SearchView.OnQueryTextListener queryTextListener = new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query)
        {
            Log.d("TAG","You queried for="+query); // Here it prints correct query input. but doesnot starting the new activity.
            Intent intent3 = new Intent(getApplicationContext(),ItemListActivity.class);
            intent3.putExtra("FetchType","ItemSearch");
            intent3.putExtra("CatId",query);
            startActivity(intent3);
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            return false;
        }
    };

    searchView.setOnQueryTextListener(queryTextListener);
    return super.onCreateOptionsMenu(menu);
}