在转移到api23后,RecyclerView在不同的页面上显示每个视图

时间:2016-05-28 18:26:57

标签: android android-recyclerview

enter image description here

我今天已经从api 22搬到了23,我的Recycler View呈现了不受欢迎的行为。它将每一行 - 视图放在一个单独的页面上。 我很抱歉在一个地方放了多个班级,但由于“未格式化”的代码,我无法提交问题 请参阅以下内容:

    <?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@color/grey">

        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:layout_width="fill_parent"
                  android:layout_height="100dp"
                  android:layout_marginBottom="1dp"
                  android:padding="10dp"
                  android:background="@drawable/ripple"
                  >

        <ImageView
            android:id="@+id/listIcon"
            android:layout_width="80dp"
            android:layout_height="80dp"
            android:layout_marginRight="8dp"
            android:src="@drawable/ic_launcher"
            />


        <TextView
            android:id="@+id/listTitle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/listIcon"
            android:textSize="16sp"
            android:textStyle="bold"
            android:text="lorum ipsum"
            android:textColor="@color/black"


            />

        <TextView
            android:id="@+id/listText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@id/listIcon"
            android:textSize="12sp"
            android:layout_below="@id/listTitle"
            android:text="lorum ipsum"
            />


    </RelativeLayout>
</RelativeLayout>

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:theme="@style/Theme.AppCompat.Light.DarkActionBar">


    <LinearLayout

        android:id="@+id/containerL"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">


    </LinearLayout>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/trainingView"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

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

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/add_wrkt_fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        android:elevation="@dimen/fab_elevation"
        android:onClick="showAddListDialog"
        android:src="@drawable/icon_add"/>


</RelativeLayout>


    public class WorkoutPickerAdapter extends FirebaseRecyclerViewAdapter<RowInfo, WorkoutPickerAdapter.MyViewHolder> {


    private static ClickListener clickListener;

    public WorkoutPickerAdapter(Class<RowInfo> modelClass, int modelLayout, Class<MyViewHolder> viewHolderClass, Query ref) {
        super(modelClass, modelLayout, viewHolderClass, ref);
    }

    public void setClickListener(ClickListener clickListener) {
        this.clickListener = clickListener;
    }


    public static class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

        TextView title;
        TextView text;
        ImageView icon;


        public MyViewHolder(View itemView) {
            super(itemView);

            title = (TextView) itemView.findViewById(R.id.listTitle);
            icon = (ImageView) itemView.findViewById(R.id.listIcon);
            text = (TextView) itemView.findViewById(R.id.listText);
            itemView.setOnClickListener(this);

        }

        @Override
        public void onClick(View view) {
            if (clickListener != null) {
                clickListener.itemClicked(view, getPosition());
            }

        }
    }

    int icons[] = {R.drawable.ex_bench_press, R.drawable.ex_incline_press, R.drawable.ex_dumbbell_flyes, R.drawable.ex_dips,
            R.drawable.ex_triceps_extension,
            R.drawable.ex_deadlift, R.drawable.ex_pull_up, R.drawable.ex_dumbbell_rows, R.drawable.ex_shrugs, R.drawable.ex_ezbar_curl,
            R.drawable.ex_hammer_curl,
            R.drawable.ex_squat, R.drawable.ex_legpress, R.drawable.ex_legcurls, R.drawable.ex_calvesraise, R.drawable.ex_military_press,
            R.drawable.ex_lateralraise, R.drawable.ex_barbell_rows, R.drawable.ez_barbell_curl,
            R.drawable.ic_launcher


    };


    @Override
    protected void populateViewHolder(MyViewHolder viewHolder, RowInfo model, int position) {
        viewHolder.title.setText(model.getTitle());
        viewHolder.text.setText(model.getText());
        String typeClean = model.getTypeClean();



    public class WorkoutPicker extends Fragment implements WorkoutPickerAdapter.ClickListener {


    private RecyclerView recyclerView;
    private FloatingActionButton fab;
    private WorkoutPickerAdapter adapter;
    private String encodedEmail;


    public WorkoutPicker() {

    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.activity_workout_picker, container, false);

        encodedEmail = PreferenceManager.getDefaultSharedPreferences(getActivity()).
                getString("email", null);


        Firebase workoutRecords = new Firebase("https://personalgymlog.firebaseio.com/workout").child(encodedEmail);
        adapter = new WorkoutPickerAdapter(RowInfo.class, R.layout.rv_row, WorkoutPickerAdapter.MyViewHolder.class, workoutRecords);
        adapter.setClickListener(this);


        LinearLayoutManager mLayoutManager;
        mLayoutManager = new LinearLayoutManager(getActivity());
        mLayoutManager.setReverseLayout(true);
        mLayoutManager.setStackFromEnd(true);


        recyclerView = (RecyclerView) v.findViewById(R.id.trainingView);
        recyclerView.setLayoutManager(mLayoutManager);
        recyclerView.setAdapter(adapter);
        setUpItemTouchHelper();


        fab = (FloatingActionButton) v.findViewById(R.id.add_wrkt_fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showAddListDialog();
            }
        });

        return v;

    }

    private void setUpItemTouchHelper() {
        ItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT) {
            @Override
            public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
                return false;
            }

            @Override
            public void onSwiped(RecyclerView.ViewHolder viewHolder, int swipeDir) {
                int position = viewHolder.getAdapterPosition();
                String listId = adapter.getRef(position).getKey();
                Firebase listToRemoveRef = new Firebase("https://personalgymlog.firebaseio.com/workout").child(encodedEmail).child(listId);
                Firebase listToRemoveRef2 = new Firebase("https://personalgymlog.firebaseio.com/exercises").child(encodedEmail).child(listId);
                listToRemoveRef.removeValue();
                listToRemoveRef2.removeValue();
            }

            @Override
            public int getSwipeDirs(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
                if (viewHolder.getAdapterPosition() == 0) return 0;
                return super.getSwipeDirs(recyclerView, viewHolder);
            }
        };

        ItemTouchHelper itemTouchHelper = new ItemTouchHelper(simpleItemTouchCallback);
        itemTouchHelper.attachToRecyclerView(recyclerView);
    }


    @Override
    public void onResume() {
        super.onResume();
        adapter.setClickListener(this);
    }

1 个答案:

答案 0 :(得分:3)

修正了父(主)布局的高度

  
angular.module('inspector.location', [])
.controller('LocationDisplayController', ['ResultService',
function(ResultService) {
  var controller = this;
  controller.inspections = ResultService.inspections;
}]);

LocationDisplayController.$inject = ['ResultService']