Android Stackoverflow错误:ViewGroup.jumpDrawablesToCurrentState

问题描述 投票:0回答:1

我有个问题。我收到了Stackoverflow错误。我试过减少布局等等。但没有任何效果。

我有一个视图寻呼机,在片段中是recyclerviews 4次。 (每个一个)。 inflater Code

View root = inflater.inflate(R.layout.content_main, container, false);

片段中的一个布局例如:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView
    android:id="@+id/list_view"
    xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_margin="10dp"
    android:layout_marginTop="15dp"
    android:layout_height="wrap_content" />

这是RecyclerView项目的布局

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
    android:id="@+id/cv"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_margin="20dp"
    android:clickable="true"
    android:background="?attr/selectableItemBackground"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:gravity="center|left"
        android:padding="10dp"
        android:clickable="true"
        android:background="?attr/selectableItemBackground"
        >

        <ImageView
            android:id="@+id/album_cover"
            android:layout_width="33dp"
            android:layout_height="50dp"
            android:layout_marginRight="16dp"
            android:src="@drawable/ic_supervisor_account_black_24dp" />

        <TextView
            android:id="@+id/album_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="Artistname"
            android:textColor="#000000"
            android:textSize="15sp" />


    </LinearLayout>

</android.support.v7.widget.CardView>

一个布局具有相对布局,但在我做出一些更改之前它可以工作:

 <android.support.v7.widget.CardView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/cv"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:clickable="true"
        android:background="?attr/selectableItemBackground"
        android:layout_margin="10dp">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="16dp"
            android:clickable="true"
            android:longClickable="true"
            android:background="?attr/selectableItemBackground"
            >

            <ImageView
                android:id="@+id/album_cover"
                android:layout_width="66dp"
                android:layout_height="50dp"
                android:layout_alignParentLeft="true"
                android:layout_alignParentTop="true"
                android:layout_marginRight="16dp"
                android:src="@drawable/spring_276014_640" />

            <TextView
                android:id="@+id/album_name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_toRightOf="@+id/album_cover"
                android:text="Albumtitel"
                android:textColor="#000000"
                android:textSize="20sp" />

            <TextView
                android:id="@+id/album_artist"
                android:layout_width="wrap_content"
                android:layout_marginTop="5dp"
                android:layout_height="wrap_content"
                android:layout_below="@+id/album_name"
                android:layout_toRightOf="@+id/album_cover"
                android:text="von Artist xy" />

        </RelativeLayout>

    </android.support.v7.widget.CardView>

捕获视图表是不可能的,因为应用程序在更改布局之前会关闭。

位图缩放。

这是我的适配器:

public class DefaultAdapter extends RecyclerView.Adapter<DefaultAdapter.SongViewHolder> {
private Context con;
private List<String> names;
boolean useplaylist;

// Provide a reference to the views for each data item
// Complex data items may need more than one view per item, and
// you provide access to all the views for a data item in a view holder
public static class SongViewHolder extends RecyclerView.ViewHolder {
    CardView cv;
    TextView title;

    SongViewHolder(View itemView) {
        super(itemView);
        cv = (CardView)itemView.findViewById(R.id.cv);
        title = (TextView)itemView.findViewById(R.id.album_name);
    }
}

// Provide a suitable constructor (depends on the kind of dataset)
public DefaultAdapter(Context context,List<String> names,boolean playlist) {
    con = context;
    this.names = names;
    useplaylist = playlist;
}

// Create new views (invoked by the layout manager)
@Override
public SongViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
    View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.playlist_item, viewGroup, false);



    SongViewHolder pvh = new SongViewHolder(v);
    return pvh;
}

@Override
public void onBindViewHolder(SongViewHolder personViewHolder, int i) {
    personViewHolder.title.setText(names.get(i));
}

// Return the size of your dataset (invoked by the layout manager)
@Override
public int getItemCount() {
    return names.size();
}

@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
    super.onAttachedToRecyclerView(recyclerView);
}
}

日志:

java.lang.StackOverflowError: stack size 8MB\n
    at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:6108)
    at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:6112)
    at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:6112)
    at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:6112)
    at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:6112)
    at android.view.ViewGroup.jumpDrawablesToCurrentState(ViewGroup.java:6112)

有人能帮助我吗?

android android-fragments android-recyclerview android-viewpager stack-overflow
1个回答
0
投票

问题解决了。

我不知道错误在哪里,但maby它是一个空列表或ImageAssets,我用矢量资产替换并激活Gradle中的Libary。

对于在视图页面中具有相同问题的thoos:停用所有片段并将其单独启用,以测试错误的位置。

© www.soinside.com 2019 - 2024. All rights reserved.