为recyclerview演示显示错误

时间:2017-05-15 04:57:48

标签: android android-recyclerview

Need output like this image

but getting like this

我正面临着recycleview的问题。我想用collapsingTool栏和嵌套滚动来完成一项任务。在该嵌套滚动中,我想使用回收器视图来获取图像。

05-15 10:07:37.227 3660-3660/com.example.welcome.dem E/AndroidRuntime: FATAL EXCEPTION: main
                                                                   Process: com.example.welcome.dem, PID: 3660
                                                                   java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.welcome.dem/com.example.welcome.dem.MainActivity}: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class android.support.constraint.ConstraintLayout
                                                                       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
                                                                       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
                                                                       at android.app.ActivityThread.-wrap12(ActivityThread.java)
                                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
                                                                       at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                       at android.os.Looper.loop(Looper.java:154)
                                                                       at android.app.ActivityThread.main(ActivityThread.java:6119)`this is the highlighed error`
                                                                       at java.lang.reflect.Method.invoke(Native Method)
                                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
                                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
                                                                    Caused by: android.view.InflateException: Binary XML file line #2: Binary XML file line #2: Error inflating class android.support.constraint.ConstraintLayout
                                                                    Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class android.support.constraint.ConstraintLayout
                                                                    Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.constraint.ConstraintLayout" on path: DexPathList[[zip file "/data/app/com.example.welcome.dem-1/base.apk", zip file "/data/app/com.example.welcome.dem-1/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.welcome.dem-1/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.welcome.dem-1/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.welcome.dem-1/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.welcome.dem-1/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.welcome.dem-1/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.welcome.dem-1/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.welcome.dem-1/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.welcome.dem-1/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.welcome.dem-1/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.welcome.dem-1/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.welcome.dem-1/lib/x86, /system/lib, /vendor/lib]]
                                                                       at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
                                                                       at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
                                                                       at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
                                                                       at android.view.LayoutInflater.createView(LayoutInflater.java:609)
                                                                       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787)
                                                                       at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
                                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
                                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
                                                                       at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
                                                                       at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292)
                                                                       at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
                                                                       at com.example.welcome.dem.MainActivity.onCreate(MainActivity.java:19)
                                                                       at android.app.Activity.performCreate(Activity.java:6679)
                                                                       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
                                                                       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
                                                                       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
                                                                       at android.app.ActivityThread.-wrap12(ActivityThread.java)
                                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
                                                                       at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                       at android.os.Looper.loop(Looper.java:154)
                                                                       at android.app.ActivityThread.main(ActivityThread.java:6119)
                                                                       at java.lang.reflect.Method.invoke(Native Method)
                                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
05-15 10:07:37.227 3660-3660/com.example.welcome.dem E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

主要活动

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

public class MainActivity extends AppCompatActivity {
 RecyclerView recyclerView;
 VendorListAdapter vdAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);`issues showing on this line`
    recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
    vdAdapter = new VendorListAdapter(this, Data.getData());
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    recyclerView.setAdapter(vdAdapter);

}
}

Data.java

import java.util.ArrayList;`enter code here`
public class Data {
public static ArrayList<VendorList> getData() {
    ArrayList<VendorList> listVendors = new ArrayList<>();
    int[] images = {
            R.drawable.bed1,
            R.drawable.bed2,
            R.drawable.bed3,
            R.drawable.bed4,
            R.drawable.bed5
    };
    String[] vendorName = {"LEE PALACE", "RESIDENCY", "CLARION", "RADISON", "VIJAY PARK"};
    String[] price = {"1000INR", "2000INR", "3000INR", "4000INR", "5000INR"};

    for (int i = 0; i < images.length; i++) {
        VendorList list_Vendor = new VendorList();
        list_Vendor.setImageView(images[i]);
        list_Vendor.setVendor_name(vendorName[i]);
        list_Vendor.setPrice(price[i]);
        listVendors.add(list_Vendor);
    }
    return listVendors;
    }
}

VendorList.java

import android.widget.ImageView;`code for vendor list`
import android.widget.TextView;
public class VendorList {
private String  vendor_name, price;
private int imageView;

public VendorList() {
}

public VendorList(String vendor_name, String price, int imageView) {
    this.vendor_name = vendor_name;
    this.price = price;
    this.imageView = imageView;
}

public String getVendor_name() {
    return vendor_name;
}

public void setVendor_name(String vendor_name) {
    this.vendor_name = vendor_name;
}

public String getPrice() {
    return price;
}

public void setPrice(String price) {
    this.price = price;
}

public int getImageView() {
    return imageView;
}

public void setImageView(int imageView) {
    this.imageView = imageView;
}
}

VendorListAdapter.java

import android.support.v7.widget.RecyclerView;`vendorlistadaptor code`
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.List;

public class VendorListAdapter extends RecyclerView.Adapter<VendorListAdapter.MyViewHolder> {
 List<VendorList> listVendor;


public VendorListAdapter(MainActivity mainActivity, List<VendorList> listVendor) {
    this.listVendor = listVendor;
}

@Override
public VendorListAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View itemView = LayoutInflater.from(parent.getContext())
            .inflate(R.layout.vendor_list_card_view, parent, false);
    return new MyViewHolder(itemView);
}

@Override
public void onBindViewHolder(VendorListAdapter.MyViewHolder holder, int position) {
    VendorList vendorList = listVendor.get(position);

    holder.imageView.setImageResource(vendorList.getImageView());
    holder.vendor_name.setText(vendorList.getVendor_name());
    holder.price.setText(vendorList.getPrice());
}

@Override
public int getItemCount() {
    return listVendor.size();
}

public class MyViewHolder extends RecyclerView.ViewHolder {
    public ImageView imageView;
    public TextView vendor_name, price;

    public MyViewHolder(View itemView) {
        super(itemView);
        imageView = (ImageView) itemView.findViewById(R.id.image_view);
        vendor_name = (TextView) itemView.findViewById(R.id.vendor_name);
        price = (TextView) itemView.findViewById(R.id.vendor_price);
    }
}

}

activity_main.xml中

<android.support.constraint.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.welcome.dem.MainActivity">

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


    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scrollbars="vertical" />

</RelativeLayout>

</android.support.constraint.ConstraintLayout>

collapse_vendor_page.xml

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

<android.support.design.widget.TabLayout
    android:id="@+id/Vendor_tabLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="@dimen/fourty_dp"
    android:background="@color/black"
    android:minHeight="?attr/actionBarSize"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

</android.support.design.widget.TabLayout>

<android.support.design.widget.CoordinatorLayout xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true"
    android:fitsSystemWindows="true">


    <android.support.design.widget.AppBarLayout
        android:id="@+id/Vendor_MyAppbar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/two_twenty_five_dp"
        android:fitsSystemWindows="true">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapse_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="@color/colorAccent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <ImageView
                android:id="@+id/bgheader"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                android:scaleType="fitXY"
                android:src="@drawable/hotel5"
                app:layout_collapseMode="pin" />

            <RelativeLayout
                android:id="@+id/transulent_relative"
                android:layout_width="match_parent"
                android:layout_height="160dp"
                android:layout_marginBottom="@dimen/thirty_five_dp"
                android:layout_marginTop="@dimen/thirty_five_dp"
                android:background="@color/transulent_white"
                android:theme="@android:style/Theme.Translucent">

                <TextView
                    android:id="@+id/wedding_trip"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:text="@string/wedding_trip"
                    android:textColor="@color/white"
                    android:textSize="@dimen/twenty_five_sp"
                    android:textStyle="bold" />

                <TextView
                    android:id="@+id/bangalore"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@+id/wedding_trip"
                    android:gravity="center"
                    android:text="@string/bangalore"
                    android:textColor="@color/black"
                    android:textSize="@dimen/eighteen_sp"
                    android:textStyle="bold" />

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginBottom="@dimen/ten_dp"
                    android:layout_marginEnd="@dimen/thirty_five_dp"
                    android:layout_marginLeft="@dimen/thirty_five_dp"
                    android:layout_marginRight="@dimen/thirty_five_dp"
                    android:layout_marginStart="@dimen/thirty_five_dp"
                    android:layout_marginTop="@dimen/sixty_dp"
                    android:gravity="center"
                    android:orientation="horizontal">

                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="@dimen/ten_dp"
                        android:layout_marginStart="@dimen/ten_dp"
                        android:orientation="vertical">

                        <ImageView
                            android:id="@+id/img1"
                            android:layout_width="wrap_content"
                            android:layout_height="@dimen/sixty_dp"
                            android:layout_gravity="center"
                            android:src="@drawable/vendor_offer" />

                        <TextView
                            android:id="@+id/offers"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center"
                            android:text="@string/offers"
                            android:textColor="@color/white"
                            android:textSize="@dimen/twenty_sp"
                            android:textStyle="bold" />
                    </LinearLayout>

                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="@dimen/eighteen_dp"
                        android:layout_marginStart="@dimen/eighteen_dp"
                        android:orientation="vertical">

                        <ImageView
                            android:id="@+id/img2"
                            android:layout_width="wrap_content"
                            android:layout_height="@dimen/sixty_dp"
                            android:layout_gravity="center"
                            android:src="@drawable/vendor_heart_in" />

                        <TextView
                            android:id="@+id/favorites"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center"
                            android:text="@string/vendor_favorites"
                            android:textColor="@color/white"
                            android:textSize="@dimen/twenty_sp"
                            android:textStyle="bold" />

                    </LinearLayout>

                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="@dimen/eighteen_dp"
                        android:layout_marginStart="@dimen/eighteen_dp"
                        android:orientation="vertical">

                        <ImageView
                            android:id="@+id/img3"
                            android:layout_width="wrap_content"
                            android:layout_height="@dimen/sixty_dp"
                            android:layout_gravity="center"
                            android:src="@drawable/vendor_close" />

                        <TextView
                            android:id="@+id/ignored"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center"
                            android:text="@string/ignored"
                            android:textColor="@color/white"
                            android:textSize="@dimen/twenty_sp"
                            android:textStyle="bold" />
                    </LinearLayout>

                </LinearLayout>

            </RelativeLayout>

            <android.support.v7.widget.Toolbar
                android:id="@+id/Vendor_MyToolbar"
                android:layout_width="match_parent"
                android:layout_height="@dimen/fourty_dp"
                app:layout_collapseMode="pin" />

        </android.support.design.widget.CollapsingToolbarLayout>


    </android.support.design.widget.AppBarLayout>


    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="fill_vertical"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <include
            layout="@layout/vendor_list_card_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </android.support.v4.widget.NestedScrollView>

    <com.github.clans.fab.FloatingActionMenu

        android:id="@+id/fab_menu"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_gravity="bottom|end"
        android:layout_marginEnd="@dimen/twenty_dp"
        android:layout_marginRight="@dimen/twenty_dp"
        android:layout_marginTop="@dimen/fourty_five_dp"
        app:menu_fab_label="Floating Action Menu"
        app:menu_fab_size="normal"
        app:menu_labels_colorNormal="@color/ash"
        app:menu_labels_colorPressed="#444"
        app:menu_labels_colorRipple="#66efecec"
        app:menu_labels_cornerRadius="3dp"
        app:menu_labels_ellipsize="none"
        app:menu_labels_textColor="@color/white">

    </com.github.clans.fab.FloatingActionMenu>

</android.support.design.widget.CoordinatorLayout>


</RelativeLayout>

vendor_list_cardview.xml

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

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="fill_vertical"
    >

<android.support.v7.widget.CardView
    android:id="@+id/card_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginEnd="@dimen/three_dp"
    android:layout_marginLeft="@dimen/three_dp"
    android:layout_marginRight="@dimen/three_dp"
    android:layout_marginStart="@dimen/three_dp"
    android:layout_marginTop="@dimen/three_dp">

    <RelativeLayout
        android:id="@+id/relative_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

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

            <ImageView
                android:id="@+id/image_view"
                android:layout_width="match_parent"
                android:layout_height="@dimen/hundred_seventy_three_dp"
                android:scaleType="fitXY" />
        </LinearLayout>

        <TextView
            android:id="@+id/vendor_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/linear_layout"
            android:layout_marginBottom="@dimen/twenty_dp"

            android:textSize="@dimen/thirty_sp"
            android:textStyle="bold"
            android:textColor="@color/limeGreen"
            android:layout_marginStart="@dimen/ten_dp"
            android:layout_marginLeft="@dimen/ten_dp"/>

        <LinearLayout
            android:id="@+id/linear_layout2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="@dimen/ten_dp"
            android:layout_marginLeft="@dimen/two_ten_dp"
            android:layout_marginStart="@dimen/two_ten_dp"
            android:layout_marginTop="@dimen/ten_dp"
            android:background="@color/transulent_black"
            android:gravity="right"
            android:orientation="vertical">

            <LinearLayout
                android:id="@+id/linear_layout3"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="right"
                android:orientation="horizontal"
                android:layout_marginRight="@dimen/ten_dp"
                android:layout_marginEnd="@dimen/ten_dp">

                <ImageView
                    android:id="@+id/image_vendor_close"
                    android:layout_width="wrap_content"
                    android:layout_height="@dimen/sixty_dp"
                    android:src="@drawable/vendor_close"
                    />

                <ImageView
                    android:id="@+id/image_vendor_white_hrt"
                    android:layout_width="wrap_content"
                    android:layout_height="@dimen/sixty_dp"
                    android:src="@drawable/vendor_white_heart_in"
                    />

            </LinearLayout>

            <RatingBar
                android:id="@+id/rating"
                style="@style/customRatingBar"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="fill_horizontal"
                android:rating="3.5"
               />

            <TextView
                android:id="@+id/vendor_price"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/five_dp"
                android:gravity="right"
                android:textColor="@color/white"
                android:textSize="@dimen/twenty_sp"
                android:textStyle="bold"
                android:layout_marginRight="@dimen/ten_dp"
                android:layout_marginEnd="@dimen/ten_dp"/>

            <TextView
                android:id="@+id/vendor_paynow"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/five_dp"
                android:gravity="right"
                android:text="@string/pay_now"
                android:textColor="@color/limeGreen"
                android:textSize="@dimen/twenty_five_sp"
                android:textStyle="bold"
                android:layout_marginRight="@dimen/ten_dp"
                android:layout_marginEnd="@dimen/ten_dp"/>
        </LinearLayout>
    </RelativeLayout>
</android.support.v7.widget.CardView>
</android.support.v4.widget.NestedScrollView>
</RelativeLayout>

0 个答案:

没有答案