我在充气CardView
时遇到错误。
内部适配器 getView():
...
LinearLayout layoutView = (LinearLayout)
inflater.inflate(R.layout.actor_layout, parent, false);
...
actor_layout.xml:
<LinearLayout
android:id="@+id/linLayoutActor"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="center" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/ImageViewActor"
android:layout_width="130dp"
android:layout_height="130dp"
android:padding="15dp" />
<TextView
android:id="@+id/textViewActorName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="15dp"
android:textColor="@android:color/holo_blue_light"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
</android.support.v7.widget.CardView>
我收到此错误:
01-24 02:16:37.660: E/AndroidRuntime(2776): android.view.InflateException: Binary XML file line #10: Error inflating class android.support.v7.widget.CardView
01-24 02:16:37.660: E/AndroidRuntime(2776): at android.view.LayoutInflater.createView(LayoutInflater.java:633)
01-24 02:16:37.660: E/AndroidRuntime(2776): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
01-24 02:16:37.660: E/AndroidRuntime(2776): at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
01-24 02:16:37.660: E/AndroidRuntime(2776): at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
01-24 02:16:37.660: E/AndroidRuntime(2776): at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
01-24 02:16:37.660: E/AndroidRuntime(2776): at com.example.demojsonparsingimage1.ActorAdapter.getView(ActorAdapter.java:45)
答案 0 :(得分:0)
要将CardView添加到Eclipse Android项目,您需要将其添加为库项目。应该在/ extras / android / support / v7 / cardview中,Eclipse应该能够为你导入它。