无法像Playstore

时间:2018-04-28 07:26:38

标签: java android xml user-interface

您好我正在开发一个应用程序,我必须制作一个类似于Playtstore的UI,我看到了这个tutorial但现在我的问题是我无法添加不同的 不同行和第二行的文字即使在设置高度和宽度后,它似乎也不会受到影响。 如果有人可以帮助我,我会陷入困境 我的代码如下

 @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {

            int[] images = {R.drawable.vancouver,R.drawable.party,R.drawable.hands_ip,R.drawable.dj};
            // Inflate the layout for this fragment
            allSampleData = new ArrayList<SectionDataModel>();
            createDummyData();

            HorizontalAdapter firstAdapter = new HorizontalAdapter(images);
            View view = inflater.inflate(R.layout.fragment_home, container, false);
            NestedScrollView nestedScrollView = view.findViewById(R.id.scrollView);
            llm = new LadderLayoutManager(1.5f, 0.85f, LadderLayoutManager.HORIZONTAL).
                    setChildDecorateHelper(new LadderLayoutManager
                            .DefaultChildDecorateHelper(getResources().getDimension(R.dimen.item_max_elevation)));
            llm.setChildPeekSize((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
                    30, getResources().getDisplayMetrics()));
            //llm.setReverse(true);
            /*llm.setMaxItemLayoutCount(5);

            rcv = (RecyclerView) view.findViewById(R.id.rcv);
            rcv.setLayoutManager(llm);

            new LadderSimpleSnapHelper().attachToRecyclerView(rcv);
            adapter = new HSAdapter();
            rcv.setAdapter(adapter);

            multi_scroll_recyclerview = (RecyclerView)view.findViewById(R.id.multi_scroll_recyclerview);
            multi_scroll_recyclerview.setNestedScrollingEnabled(false);
            multi_scroll_layout_manager = new LinearLayoutManager(getActivity(),LinearLayoutManager.VERTICAL,false);
            multi_scroll_recyclerview.setLayoutManager(multi_scroll_layout_manager);
            multi_scroll_adapter = new RecyclerViewDataAdapter(getActivity(),allSampleData);
            multi_scroll_recyclerview.setAdapter(multi_scroll_adapter);
            multi_scroll_recyclerview.setHasFixedSize(true);*/






       /* MultiSnapRecyclerView firstRecyclerView = (MultiSnapRecyclerView)view.findViewById(R.id.first_recycler_view);
        LinearLayoutManager firstManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false);
        firstRecyclerView.setLayoutManager(firstManager);
        firstRecyclerView.setAdapter(firstAdapter);

        HorizontalAdapter secondAdapter = new HorizontalAdapter(images);
        MultiSnapRecyclerView secondRecyclerView =(MultiSnapRecyclerView) view.findViewById(R.id.second_recycler_view);
        LinearLayoutManager secondManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false);
        secondRecyclerView.setLayoutManager(secondManager);
        secondRecyclerView.setAdapter(secondAdapter);

        HorizontalAdapter thirdAdapter = new HorizontalAdapter(images);
        MultiSnapRecyclerView thirdRecyclerView = (MultiSnapRecyclerView)view.findViewById(R.id.third_recycler_view);
        LinearLayoutManager thirdManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false);
        thirdRecyclerView.setLayoutManager(thirdManager);
        thirdRecyclerView.setAdapter(thirdAdapter);*/


            return view;

        }
        public void createDummyData() {
            for (int i = 1; i <= 5; i++) {

                SectionDataModel dm = new SectionDataModel();
                dm.setHeaderTitle("Clubs");
                dm.setHeadertitle2("Lounge");
                dm.setHeadertitle3("Cafe");
                dm.setHeadertitle4("Rooftop");
                ArrayList<SingleItemModel> singleItem = new ArrayList<SingleItemModel>();
                for (int j = 0; j <= 5; j++) {
                    singleItem.add(new SingleItemModel("Item " + j, "URL " + j));
                }

                dm.setAllItemsInSection(singleItem);

                allSampleData.add(dm);//line which is causing issue

            }
        }
code for adapter

    public class SectionListDataAdapter extends RecyclerView.Adapter<SectionListDataAdapter.SingleItemRowHolder> {

        private ArrayList<SingleItemModel> itemsList;
        private Context mContext;

        public SectionListDataAdapter(Context context, ArrayList<SingleItemModel> itemsList) {
            this.itemsList = itemsList;
            this.mContext = context;
        }

        @Override
        public SingleItemRowHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
            View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.list_single_card, null);
            SingleItemRowHolder mh = new SingleItemRowHolder(v);
            return mh;
        }

        @Override
        public void onBindViewHolder(SingleItemRowHolder holder, int i) {

            SingleItemModel singleItem = itemsList.get(i);

            holder.tvTitle.setText(singleItem.getName());


           /* Glide.with(mContext)
                    .load(feedItem.getImageURL())
                    .diskCacheStrategy(DiskCacheStrategy.ALL)
                    .centerCrop()
                    .error(R.drawable.bg)
                    .into(feedListRowHolder.thumbView);*/
        }

        @Override
        public int getItemCount() {
            return (null != itemsList ? itemsList.size() : 0);
        }

        public class SingleItemRowHolder extends RecyclerView.ViewHolder {

            protected TextView tvTitle;

            protected ImageView itemImage;


            public SingleItemRowHolder(View view) {
                super(view);

                this.tvTitle = (TextView) view.findViewById(R.id.tvTitle);
                this.itemImage = (ImageView) view.findViewById(R.id.itemImage);


                view.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {


                        //Toast.makeText(v.getContext(), tvTitle.getText(), Toast.LENGTH_SHORT).show();

                    }
                });


            }

        }

    }

My code for model class

    public class SectionDataModel {
        private String headerTitle,headertitle2,headertitle3,headertitle4;
        private ArrayList<SingleItemModel> allItemsInSection;


        public SectionDataModel() {

        }
        public SectionDataModel(String headerTitle, ArrayList<SingleItemModel> allItemsInSection) {
            this.headerTitle = headerTitle;
            this.allItemsInSection = allItemsInSection;
        }



        public String getHeaderTitle() {
            return headerTitle;
        }

        public String getHeadertitle2() {
            return headertitle2;
        }

        public String getHeadertitle3() {
            return headertitle3;
        }

        public String getHeadertitle4() {
            return headertitle4;
        }

        public void setHeaderTitle(String headerTitle) {
            this.headerTitle = headerTitle;
        }

        public void setHeadertitle2(String headertitle2) {
            this.headertitle2 = headertitle2;
        }

        public void setHeadertitle3(String headertitle3) {
            this.headertitle3 = headertitle3;
        }

        public void setHeadertitle4(String headertitle4) {
            this.headertitle4 = headertitle4;
        }

        public ArrayList<SingleItemModel> getAllItemsInSection() {
            return allItemsInSection;
        }

        public void setAllItemsInSection(ArrayList<SingleItemModel> allItemsInSection) {
            this.allItemsInSection = allItemsInSection;
        }

    }

listitem.xml

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"

        android:background="?android:selectableItemBackground"
        android:orientation="vertical"
        android:padding="5dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">


            <com.ct.listrtrial.Custom.CustomTextViewMedium
                android:id="@+id/itemTitle"
                android:layout_width="0dp"
                android:layout_weight="8"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_centerVertical="true"
                android:layout_gravity="center_vertical"
                android:layout_toLeftOf="@+id/btnMore"
                android:text="Sample title"
                android:textColor="@android:color/white"
                android:textSize="27sp" />
            <ImageView
                android:id="@+id/btnMore"
                android:layout_width="0dp"
                android:layout_weight="0.8"
                android:layout_marginTop="13dp"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:background="@drawable/ic_more_horiz_black_24dp"
                android:textColor="#FFF" />


        </LinearLayout>

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_view_list"
            android:layout_width="match_parent"
            android:layout_marginTop="10dp"
            android:layout_height="160dp"
            android:layout_gravity="center_vertical"
            android:orientation="horizontal" />


    </LinearLayout>

main fragment.xml

    <android.support.v4.widget.NestedScrollView android:layout_width="match_parent"
        android:layout_height="match_parent"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/scrollView"
        android:fillViewport="true"
        android:background="@color/colorPrimary"
        xmlns:android="http://schemas.android.com/apk/res/android">
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/rcv"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_gravity="center_horizontal"
            android:layout_weight="1"
            android:paddingBottom="10dp"
            android:paddingTop="10dp" />

        <android.support.v7.widget.RecyclerView

            android:id="@+id/multi_scroll_recyclerview"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_weight="1">

        </android.support.v7.widget.RecyclerView>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">


        </LinearLayout>

    </LinearLayout>
    </android.support.v4.widget.NestedScrollView>

listsinglecard.xml

    <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="220dp"
        android:layout_marginLeft="18dp"
        android:layout_height="200dp"
        app:cardCornerRadius="65dp"

        >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="?android:selectableItemBackground"
            android:orientation="vertical">

            <ImageView
                android:id="@+id/itemImage"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_gravity="center_horizontal"
                android:scaleType="centerCrop"
                android:src="@drawable/vancouver" />


            <TextView
                android:id="@+id/tvTitle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/itemImage"
                android:gravity="center"
                android:padding="5dp"
                android:visibility="gone"
                android:text="Sample title"
                android:textColor="@android:color/black"
                android:textSize="18sp" />


        </LinearLayout>

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

0 个答案:

没有答案