我收到一条警告,例如无条件布局通胀导致布局退出,应用程序崩溃。我需要在不崩溃的情况下对此布局进行充气。 崩溃在以下代码上。 我有自定义适配器集的代码。
public class CustomAdapter extends BaseAdapter {
private List<Response.NodesEntity> mMovieitem;
private Context mContext;
private LayoutInflater inflater;
public CustomAdapter(Context mContext, List<Response.NodesEntity> mMovieitem) {
this.mContext = mContext;
this.mMovieitem = mMovieitem;
}
@Override
public int getCount() {
return mMovieitem.size();
}
@Override
public Object getItem(int position) {
return mMovieitem.get(position);
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.s, parent, false);
Response.NodesEntity item = (Response.NodesEntity) getItem(position);
ImageView thumbnail = (ImageView) rowView.findViewById(R.id.thumbnail);
TextView title = (TextView) rowView.findViewById(R.id.title);
TextView rating = (TextView) rowView.findViewById(R.id.video_url);
String imageUrl = item.getVideoTumbnail().getSrc();
Picasso.with(mContext).load(imageUrl).into(thumbnail);
title.setText(item.getTitle());
rating.setText(item.getHlsVideo());
return rowView;
}
}
Xml采用这种格式。我正在夸大这种布局和
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:id="@+id/video_list"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="info.androidhive.materialdesign.activity.FriendsFragment">
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="250dp"
android:layout_margin="5dp">
<ImageView
android:id="@+id/thumbnail"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/background_material_light"
android:scaleType="centerCrop" />
<TextView
android:layout_marginBottom="10dp"
android:layout_gravity="bottom"
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/thumbnail"
android:layout_toEndOf="@+id/thumbnail"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:typeface="sans"
android:textSize="22sp"
android:textColor="#ffffff" />
<TextView
android:layout_marginTop="20dp"
android:id="@+id/video_url"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/title"
android:layout_toEndOf="@+id/thumbnail"
android:layout_toRightOf="@+id/thumbnail"
android:visibility="invisible"/>
</android.support.v7.widget.CardView>
</RelativeLayout>
答案 0 :(得分:0)
使用View holder方法为每行充气