我只是遇到以下错误:我该如何解决?
我有“ android.view.InflateException:二进制XML文件行#34:无法转换为尺寸:type = 0x12”。我检查了堆栈溢出中的所有解决方案,但没有解决任何问题。这是因为版本问题或其他原因。请帮忙!
谢谢
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardBackgroundColor="@color/card_background"
android:layout_margin="10dp"
android:foreground="?attr/selectableItemBackground"
android:background="@drawable/comment_background"
android:stateListAnimator="@anim/comment_selection"
android:clickable="true">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/hints"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp">
<ImageView
android:id="@+id/iv_status"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
app:srcCompat="@mipmap/ic_app_icon" />
<TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginLeft="@+id/iv_status"
android:lines="1"
android:text="@string/btn_login"
android:textColor="@color/text_color"
android:textSize="20sp" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/hints"
android:layout_marginLeft="10dp"
android:layout_marginTop="4dp"
android:layout_marginRight="10dp">
<RelativeLayout
android:id="@+id/view1"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/iv_label_priority"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="5dp"
android:src="@drawable/client" />
<TextView
android:id="@+id/tv_priority"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/iv_label_priority"
android:layout_alignBottom="@+id/iv_label_priority"
android:layout_toRightOf="@+id/iv_label_priority"
android:layout_marginLeft="5dp"
android:lines="1"
android:text="@string/btn_login"
android:textColor="@color/text_color" />
<ImageView
android:id="@+id/iv_label_date"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_below="@+id/iv_label_priority"
android:layout_marginBottom="5dp"
android:src="@drawable/client" />
<TextView
android:id="@+id/tv_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/iv_label_date"
android:layout_alignBottom="@+id/iv_label_date"
android:layout_toRightOf="@+id/iv_label_date"
android:lines="1"
android:layout_marginLeft="5dp"
android:text="@string/btn_login"
android:textColor="@color/text_color" />
<ImageView
android:id="@+id/iv_label_assign"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_below="@+id/iv_label_date"
android:layout_marginBottom="5dp"
android:src="@drawable/client" />
<TextView
android:id="@+id/tv_assign"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/iv_label_assign"
android:layout_alignBottom="@+id/iv_label_assign"
android:layout_toRightOf="@+id/iv_label_assign"
android:layout_marginLeft="5dp"
android:lines="1"
android:text="@string/btn_login"
android:textColor="@color/text_color" />
<ImageView
android:id="@+id/iv_label_task"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_below="@+id/iv_label_assign"
android:layout_marginBottom="5dp"
android:src="@drawable/client" />
<TextView
android:id="@+id/tv_task"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/iv_label_task"
android:layout_marginLeft="5dp"
android:layout_toRightOf="@+id/iv_label_task"
android:lines="1"
android:text="@string/btn_login"
android:textColor="@color/text_color" />
<ImageView
android:id="@+id/iv_label_client"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_below="@+id/iv_label_task"
android:layout_marginBottom="5dp"
android:src="@drawable/client" />
<TextView
android:id="@+id/tv_client"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/iv_label_client"
android:layout_alignBottom="@+id/iv_label_client"
android:layout_toRightOf="@+id/iv_label_client"
android:layout_marginLeft="5dp"
android:lines="1"
android:text="@string/btn_login"
android:textColor="@color/text_color" />
<ImageView
android:id="@+id/iv_label_time"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignTop="@+id/tv_date"
android:layout_alignBottom="@+id/tv_date"
android:layout_toRightOf="@+id/tv_date"
android:layout_marginLeft="100dp"
app:srcCompat="@drawable/client" />
<TextView
android:id="@+id/tv_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/iv_label_time"
android:layout_alignBottom="@+id/iv_label_time"
android:layout_toRightOf="@+id/iv_label_time"
android:layout_marginLeft="5dp"
android:lines="1"
android:text="@string/btn_login"
android:textColor="@color/text_color" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/view1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_weight="0.2"
app:srcCompat="@drawable/ic_login"
android:layout_margin="5dp"/>
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
app:srcCompat="@drawable/ic_login"
android:layout_weight="0.2"
android:layout_margin="5dp"/>
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
app:srcCompat="@drawable/ic_login"
android:layout_weight="0.2"
android:layout_margin="5dp"/>
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
app:srcCompat="@drawable/ic_login"
android:layout_weight="0.2"
android:layout_margin="5dp"/>
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
app:srcCompat="@drawable/ic_login"
android:layout_weight="0.2"
android:layout_margin="5dp" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
适配器
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.transition.TransitionManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import java.util.ArrayList;
import bd.com.rtchubs.taskapp.R;
import bd.com.rtchubs.taskapp.admin_model.AdminProjects;
public class AdminProjectsListAdapter extends RecyclerView.Adapter<AdminProjectsListAdapter.AdminProjectsListViewHolder> {
private Context context;
private ArrayList<AdminProjects> projectsList;
private int mExpandedPosition = -1;
private View itemView;
public AdminProjectsListAdapter(Context context, ArrayList<AdminProjects> projectsList) {
this.context = context;
this.projectsList = projectsList;
}
@NonNull
@Override
public AdminProjectsListViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
itemView = LayoutInflater.from(context).inflate(R.layout.admin_fragment1_individual_view, viewGroup, false);
return new AdminProjectsListViewHolder(itemView);
}
@Override
public void onBindViewHolder(@NonNull final AdminProjectsListViewHolder adminProjectsListViewHolder, final int i) {
final boolean isExpanded = i == mExpandedPosition;
adminProjectsListViewHolder.details.setVisibility(isExpanded?View.VISIBLE:View.GONE);
adminProjectsListViewHolder.itemView.setActivated(isExpanded);
adminProjectsListViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mExpandedPosition = isExpanded ? -1:i;
TransitionManager.beginDelayedTransition((ViewGroup) itemView);
notifyDataSetChanged();
}
});
AdminProjects projects = projectsList.get(i);
adminProjectsListViewHolder.tv_title.setText(projects.getProjectsName());
adminProjectsListViewHolder.tv_priority.setText(projects.getProjectsPriority());
adminProjectsListViewHolder.tv_date.setText(projects.getProjectsDate());
adminProjectsListViewHolder.tv_time.setText(projects.getProjectsTime());
adminProjectsListViewHolder.tv_task.setText(projects.getProjectsTask());
adminProjectsListViewHolder.tv_assign.setText(projects.getProjectsAssign());
adminProjectsListViewHolder.tv_client.setText(projects.getProjectsClient());
if(projects.getProjectsPriority() == 1){
adminProjectsListViewHolder.iv_status.setImageResource(R.drawable.done);
} else if(projects.getProjectsPriority() == 2){
adminProjectsListViewHolder.iv_status.setImageResource(R.drawable.progress);
} else if(projects.getProjectsPriority() == 3){
adminProjectsListViewHolder.iv_status.setImageResource(R.drawable.pending);
} else if(projects.getProjectsPriority() == 4){
adminProjectsListViewHolder.iv_status.setImageResource(R.drawable.due);
}
}
@Override
public int getItemCount() {
return projectsList.size();
}
public class AdminProjectsListViewHolder extends RecyclerView.ViewHolder {
public TextView tv_title,tv_priority,tv_date,tv_assign,tv_task,tv_client,tv_time;
public ImageView iv_status;
public RelativeLayout details;
public AdminProjectsListViewHolder(View view) {
super(view);
details = view.findViewById(R.id.details);
tv_title = view.findViewById(R.id.tv_title);
tv_priority = view.findViewById(R.id.tv_priority);
tv_date = view.findViewById(R.id.tv_date);
tv_task = view.findViewById(R.id.tv_task);
tv_time = view.findViewById(R.id.tv_time);
tv_assign = view.findViewById(R.id.tv_assign);
tv_client = view.findViewById(R.id.tv_client);
iv_status = view.findViewById(R.id.iv_status);
}
}
}
logcat
android.view.InflateException: Binary XML file line #34: Can't convert to dimension: type=0x12
at android.view.LayoutInflater.inflate(LayoutInflater.java:551)
at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
at bd.com.rtchubs.taskapp.admin_adapter.AdminProjectsListAdapter.onCreateViewHolder(AdminProjectsListAdapter.java:34)
at bd.com.rtchubs.taskapp.admin_adapter.AdminProjectsListAdapter.onCreateViewHolder(AdminProjectsListAdapter.java:19)
at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:6794)
at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5975)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5858)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5854)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2230)
at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1557)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1517)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:612)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3924)
at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3641)
at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:4194)
at android.view.View.layout(View.java:18010)
at android.view.ViewGroup.layout(ViewGroup.java:5817)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:344)
at android.widget.FrameLayout.onLayout(FrameLayout.java:281)
at android.view.View.layout(View.java:18010)
at android.view.ViewGroup.layout(ViewGroup.java:5817)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:344)
at android.widget.FrameLayout.onLayout(FrameLayout.java:281)
at android.view.View.layout(View.java:18010)
at android.view.ViewGroup.layout(ViewGroup.java:5817)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1080)
at android.view.View.layout(View.java:18010)
at android.view.ViewGroup.layout(ViewGroup.java:5817)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:344)
at android.widget.FrameLayout.onLayout(FrameLayout.java:281)
at android.view.View.layout(View.java:18010)
at android.view.ViewGroup.layout(ViewGroup.java:5817)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1742)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1585)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1494)
at android.view.View.layout(View.java:18010)
at android.view.ViewGroup.layout(ViewGroup.java:5817)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:344)
at android.widget.FrameLayout.onLayout(FrameLayout.java:281)
at android.view.View.layout(View.java:18010)
at android.view.ViewGroup.layout(ViewGroup.java:5817)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1742)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1585)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1494)
at android.view.View.layout(View.java:18010)
at android.view.ViewGroup.layout(ViewGroup.java:5817)
at android.widget.FrameLayout.layoutChildren(FrameLayout.java:344)
at android.widget.FrameLayout.onLayout(FrameLayout.java:281)
at com.android.internal.policy.PhoneWindow$DecorView.onLayout(PhoneWindow.java:3175)
at android.view.View.layout(View.java:18010)
at android.view.ViewGroup.layout(ViewGroup.java:5817)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2776)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2477)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1544)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7607)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
at android.view.Choreographer.do
答案 0 :(得分:2)
检查ID为TextView
的{{1}}
tv_title
您在这里使用了 <TextView
android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginLeft="@+id/iv_status"
android:lines="1"
android:text="@string/btn_login"
android:textColor="@color/text_color"
android:textSize="20sp" />
。 android:layout_marginLeft="@+id/iv_status"
仅接受尺寸值。但您正在传递视图ID。使用有效的尺寸值