我得到一個警告,如無條件佈局通貨膨脹,導致佈局退出和應用程序崩潰。我需要膨脹此佈局而不崩潰。 崩潰是在下面的代碼。 我有自定義適配器集的代碼。從視圖適配器無條件佈局通貨膨脹
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>
您必須正確使用convertView而不是一味誇大佈局。那裏有大量的教程 –