I am using recyclerview gridview to show product. But its showing like this
this is the view
my xml view code is
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/tools"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:id="#+id/card_view"
android:layout_width="#dimen/cover_height"
android:layout_height="wrap_content"
android:layout_gravity="center"
card_view:cardUseCompatPadding="true"
android:elevation="7dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.makeramen.roundedimageview.RoundedImageView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/thumbnail"
android:src="#drawable/placeholder_image"
android:scaleType="fitXY"
app:riv_oval="false"
app:riv_corner_radius_top_left="6dp"
app:riv_corner_radius_top_right="6dp"
android:layout_height="#dimen/cover_height"
android:layout_width="match_parent" />
<pseudozero.smalam.com.finwallet.utils.TextViewPlus
android:id="#+id/tvProductTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/thumbnail"
android:textColor="#color/colorBlack"
android:textSize="15dp"
android:text="Wrist Watch"
android:padding="5dp"
app:customFont="fonts/Proxima_Nova_Bold.otf"/>
<pseudozero.smalam.com.finwallet.utils.TextViewPlus
android:id="#+id/tvProductVendor"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/tvProductTitle"
android:textSize="13dp"
android:paddingLeft="5dp"
android:paddingBottom="5dp"
android:text="Rolex"
app:customFont="fonts/Proxima_Nova_Reguler.otf"/>
<pseudozero.smalam.com.finwallet.utils.TextViewPlus
android:id="#+id/tvPriceTag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="500 BDT"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:textColor="#color/colorWhite"
android:textSize="13dp"
android:padding="10dp"
android:background="#drawable/price_tag_back_n"
app:customFont="fonts/Proxima_Nova_Bold.otf"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
I am using a card view inside linearlayout. But I am getting this
I am loading all data from server. Only the second item is going up. I want that all items will be decorated.
Use fixed height of CardView and RoundedImageView
Use attribute android:scaleType="centerCrop" instead of android:scaleType="fitXY" to RoundedImageView.
Hope this will help~
RelativeLayout Height should be wrap_content
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
to
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
And in your code you do not close parent LinearLayout.
Related
Hi i have a main recyclerview which is set to vertical and inside that recyclerview i have another recyclerview which is set to horizontal and inside horizontal recyclerview i have cardview with imageview and textview, i'm currently making my layout for android t.v so in order to work this code i have to add focus in my cardview so that user can easily navigate through the cards but the issue is if i'm adding
android:focusable="true"
in my cardview nothing works, my guess is because i have 2 recyclerviews that's why cardview is not receiving focus any idea how to fix it..
Here's my code
This is my main recyclerview
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerviewMainCarousels"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="afterDescendants"/>
This is my second recyclerview
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerviewCarousel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="beforeDescendants"/>
And this is my cardview
<androidx.cardview.widget.CardView
android:id="#+id/bollyAlbumCardView"
android:foreground="?android:attr/selectableItemBackground"
app:cardBackgroundColor="#android:color/transparent"
app:cardElevation="0dp"
app:contentPadding="3dp"
app:cardUseCompatPadding="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true">
<LinearLayout
android:padding="0dp"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_gravity="center_horizontal"
android:layout_width="180dp"
android:layout_height="180dp">
<com.hirazo.utilities.HZImageView
android:id="#+id/image"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="ContentDescription"
android:scaleType="fitXY" />
<ImageView
android:id="#+id/playIcon"
android:visibility="gone"
android:layout_centerInParent="true"
android:src="#drawable/icon_play_new"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
<TextView
android:textSize="12sp"
android:id="#+id/title"
android:paddingTop="8dp"
android:maxLines="2"
android:ellipsize="marquee"
android:layout_width="match_parent"
android:layout_height="45dp"
android:textColor="#fff" />
</LinearLayout>
</androidx.cardview.widget.CardView>
You have to add this line of code somewhere (Adapter?)
textView.setSelected(true);
I have added android-recyclerview in my app which is running fine. According to my layout i have to remove divider between cells. In list view this can easily be achieved by setting divider property to null like below in code but i am not able to find any such property in android-recyclerview. How can i achieve this in android-recyclerview.
getListView().setDivider(null);
getListView().setDividerHeight(0);
OR
android:divider="#null"
android:dividerHeight="0dp"
Recylerview xml below :
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view_contact_list_frag"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.8"
android:clickable="true"
android:focusable="true"
android:scrollbars="vertical" />
Adapter xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#drawable/recyclerview_item_borders"
android:padding="10dp">
<LinearLayout
android:id="#+id/section_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:paddingBottom="30dp"
>
<TextView
android:id="#+id/textview_section_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<de.hdodenhof.circleimageview.CircleImageView xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/circular_image_contact"
android:layout_width="#dimen/auto_complete_circular_image_dimen"
android:layout_height="#dimen/auto_complete_circular_image_dimen"
app:civ_border_color="#FF000000"
android:layout_weight="0.2"
android:src="#mipmap/ic_default_contact"
app:civ_border_width="0dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.8"
android:orientation="vertical">
<TextView
android:id="#+id/textView_contact_name"
android:layout_width="match_parent"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:textColor="#color/textDarkColor"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />
<TextView
android:id="#+id/textView_contact_number"
android:layout_width="match_parent"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:layout_marginLeft="#dimen/activity_horizontal_margin"
android:textColor="#color/textDarkColor"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />
</LinearLayout>
</LinearLayout>
Remove background from adapter
android:background="#drawable/recyclerview_item_borders"
Recyclerview don't have the divider by default. If you need to add the divider, you have to add the decoration to the recyclerview.
It is from the custom view you are using by default there is no divider. share your code thn any one can help you.
You need to change it in the List item view. Add following parameters to list item view.
card_view:cardCornerRadius="0dp"
card_view:cardElevation="0dp"
card_view:cardUseCompatPadding="true"
In list_item_view.xml
<android.support.v7.widget.CardView
android:id="#+id/card_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
card_view:cardCornerRadius="0dp"
card_view:cardElevation="0dp"
card_view:cardUseCompatPadding="true">
Then set background color of your Recycle view to its foreground color. If it is white,
In recycle_view.xml
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:background="#ffffff"
android:scrollbars="vertical"
android:layout_height="wrap_content"/>
i need to show CardViews in HorizontalScrollView like below tutorial
http://examples.javacodegeeks.com/android/core/ui/horizontalscrollview/android-horizontalscrollview-example/
and here is what i've tryed:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:weightSum="3">
<HorizontalScrollView
android:id="#+id/horizontalScrollView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<android.support.v7.widget.CardView
android:id="#+id/view2"
android:layout_width="170dp"
android:layout_height="220dp"
android:layout_alignParentEnd="true"
android:layout_alignTop="#+id/horizontalScrollView"
android:clickable="true"
android:foreground="?android:attr/selectableItemBackground"
card_view:cardCornerRadius="3dp"
card_view:cardElevation="3sp"
card_view:cardUseCompatPadding="true" />
</RelativeLayout>
</HorizontalScrollView>
<android.support.v7.widget.CardView
android:id="#+id/view5"
android:layout_width="170dp"
android:layout_height="220dp"
android:clickable="true"
android:foreground="?android:attr/selectableItemBackground"
card_view:cardCornerRadius="3dp"
card_view:cardElevation="3sp"
card_view:cardUseCompatPadding="true"
android:layout_alignTop="#+id/horizontalScrollView"
android:layout_alignParentEnd="true"
android:layout_marginEnd="33dp" />
</RelativeLayout>
But i can't use more than two cardview in this layout.(inHorizontalScrollView)
should i use another widget for this porpose or what is the problem if i need to show 5 CardView in this Horizontal ScrollView?
Cheers!
You can use RecyclerView which comes in the android support library and u can see how to add it to your project here. It is a better implementation on list view which comes with a Layout manager by which you can configure it to be used as Horizontal or vertical Scroll mode.
mRecyclerLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
I am having a play with the new Android L SDK and I can't figure out how to implement CardView. Seems like I'm missing something - any advice is very much appreciated!
So far I have the following declared as part of my activity:
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:layout_below="#+id/waitingHeader"
card_view:cardCornerRadius="4dp">
<LinearLayout
android:id="#+id/card_linear_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/notificationText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="hello"/>
<TextView
android:id="#+id/notificationTex"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="hello2"/>
</LinearLayout>
</android.support.v7.widget.CardView>
Naively I was hoping that would give me two cards with hello and hello2 however all I see is a single card with hello - the second card is missing. How can I create multiple cards using CardView?
Think of cardview as ViewGroup Like linear layout or Relative layout. If you want two cardview then use two cardview and keep root layout as Linear or Relative Layout.
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:layout_below="#+id/waitingHeader"
card_view:cardCornerRadius="4dp">
<TextView
android:id="#+id/notificationText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="hello"/>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/card_view2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:layout_below="#+id/waitingHeader"
card_view:cardCornerRadius="4dp">
<TextView
android:id="#+id/notificationTex"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="hello2"/>
</android.support.v7.widget.CardView>
I want to implement a layout like this for each row of a listview
So i created a container like this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:clickable="false"
android:focusable="false"
>
<!--List items goes here -->
</LinearLayout>
In the getView() method of my custom adapter, I inflate this xml for each box in the image above
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="300dp"
android:layout_height="500dp"
android:clickable="true"
android:focusable="true"
android:padding="10dp"
android:background="#drawable/list_item_background"
android:focusableInTouchMode="true">
<ImageView
android:id="#+id/thumbnail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="#drawable/cnbc_default_image"/>
<ImageView
android:id="#+id/supportImageView"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentLeft="true"
android:visibility="gone"
android:src="#drawable/video_play_icon"
android:paddingLeft="10dp"
android:layout_above="#+id/title"/>
<TextView
android:id="#id/title"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_above="#+id/description"
style="#style/large_news_title_text_style"/>
<TextView android:id="#id/description"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:maxLines="2"
android:ellipsize="end"
android:textSize="13sp"
style="#style/large_news_title_text_style"
android:textColor="#android:color/white" />
</RelativeLayout>
and then finally add the inflated view to the linearlayout instance using
row.addView(inflatedView);
However, the end result is first box stretching across X axis. If i inspect my layout using HierachyViewer, i do see 3 RelativeLayouts inside a LinearLayout, but the first one is occupying all the space.
The thumbnail image android:id="#+id/thumbnail", seems to be taking up match_parent attribute of the LinearLayout and not its immediate container RelativeLayout.
Clarification
The list view is from ListFragment.
When adding the box layout to the list view row container i use this method call
ViewGroup container = (ViewGroup)inflater.inflate(R.layout.list_view_row_land, parent, false);
View rowItem = inflater.inflate(R.layout.list_view_row_item,null);
container.addView(rowItem);
Solved:
The problem is solved if i modify the layout of the box to
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="500dp"
android:layout_height="300dp"
android:clickable="true"
android:focusable="true"
android:padding="10dp"
android:background="#drawable/list_item_background"
android:focusableInTouchMode="true">
<ImageView
android:id="#+id/thumbnail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="#drawable/cnbc_default_image"/>
<ImageView
android:id="#+id/supportImageView"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentLeft="true"
android:visibility="gone"
android:src="#drawable/video_play_icon"
android:paddingLeft="10dp"
android:layout_above="#+id/title"/>
<TextView
android:id="#id/title"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_above="#+id/description"
style="#style/large_news_title_text_style"/>
<TextView android:id="#id/description"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:maxLines="2"
android:ellipsize="end"
android:textSize="13sp"
style="#style/large_news_title_text_style"
android:textColor="#android:color/white" />
</RelativeLayout>
</LinearLayout>
I still don't understand why. So any explanation of why putting a LinearLayout around solves the issue will be helpful.