I'm doing a small application and am using a RecyclerView but when I emulate my application on API 19 I got small gap between the item, however if I run the same application on API 22 there is no gap (there is a screen at the end).
I'm using material design
frag_home
xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rv_videos"
android:layout_height="match_parent"
android:layout_width="match_parent"
tools:listitem="#layout/item_video"
/>
</LinearLayout>
item_card
xml
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="0dp"
app:cardPreventCornerOverlap="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:id="#+id/video_preview"
android:layout_width="match_parent"
android:layout_height="194dp"
android:scaleType="centerCrop"
tools:src="#drawable/img_error_v1"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<TextView
android:id="#+id/video_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?attr/textAppearanceHeadline6"
android:maxLines="1"
tools:text="This is a really really really really really really really really really really really long title"
/>
<TextView
android:id="#+id/video_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:maxLines="1"
android:textAppearance="?attr/textAppearanceBody2"
android:textColor="?android:attr/textColorSecondary"
tools:text="This is the URL for now"
/>
</LinearLayout>
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
Here is the image, on the left is API 22 and on the right API 19
For my application, I don't need to use CardView therefore I changed them for a LinearLayout.
You can check these post to know more about CardView and layout
Why use a CardView instead of a RelativeLayout or LinearLayout?
Advantage and disadvantage of CardView
Related
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F3E889"
android:paddingLeft="100dp"
android:paddingTop="100dp"
android:paddingEnd="100dp"
android:paddingRight="100dp"
android:paddingBottom="100dp"
android:textAlignment="center"
android:visibility="visible"
tools:context=".MainActivity">
<EditText
android:id="#+id/editTextTextPersonName4"
android:layout_width="300dp"
android:layout_height="300dp"
android:ems="100"
android:inputType="textPersonName"
android:text="I want to be a Android developer"
tools:layout_editor_absoluteX="-64dp"
tools:layout_editor_absoluteY="-46dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
This is simple code which is trying to print I want to be a Android developed but when viewed on
mobile its not showing the complete sentence.
May be you don't give a proper constraints to your editText also you don't give a proper padding to your parent layout, please try this code :
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F3E889"
android:padding="10dp"
android:textAlignment="center"
android:visibility="visible"
tools:context=".MainActivity">
<EditText
android:id="#+id/editTextTextPersonName4"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:inputType="textPersonName"
android:text="I want to be a Android developer"/>
There's 100 dp of padding on all 4 sides. That pushes all the content to the middle of the screen. It cuts off like half of the usable space.
I have a simple layout file for which I want to use a drawable in the background of main container
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/mlv_balance_detail_container"
android:layout_height="wrap_content"
android:orientation="vertical"
**android:background="#drawable/sample_drawable"** //this was causing crash in 4.4.2 API 19
android:padding="#dimen/dimen_16dp">
<TextView
android:id="#+id/tv_policy_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif"
android:letterSpacing="0.04"
tools:text="text"
android:textColor="#1d252d"
android:textSize="14sp"
android:textStyle="normal" />
<TextView
android:id="#+id/tv_total_balance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tv_policy_text"
android:layout_marginTop="8dp"
android:fontFamily="sans-serif"
android:letterSpacing="0.04"
tools:text="some text"
android:textColor="#1d252d"
android:textSize="12sp"
android:textStyle="normal" />
</RelativeLayout>
Then I tried setting the background from code using
container.setBackground(ContextCompat.getDrawable(context, R.drawable.sample_drawable));
It is still crashing, can anyone help me out here?
Thanks,
I found a working solution for this problem, although I would still look for a better answer but for the time being, I am using an ImageView inside a FrameLayout and setting app:srcCompat property of Imageview which is backward compatible.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="#drawable/sample_drawable" />
</FrameLayout>
//rest of my layout as it is
</RelativeLayout>
So I want to use 2 images. One should be on top of the other but smaller, so that the border of the image that's behind is only shown.
Take a look at these 2 photos.
Image that's behind (The border Image)
[IMG]http://i66.tinypic.com/25zgguh.jpg[/IMG]
Image that should be inside the border
[IMG]http://i67.tinypic.com/10mpgt4.jpg[/IMG]
XML CODE
<com.inthessaloniki.cityguide.view.SelectorRelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/fragment_poi_list_item"
android:layout_width="match_parent"
android:layout_height="#dimen/fragment_poi_list_recycler_item_size"
android:minHeight="#dimen/fragment_poi_list_recycler_item_size"
android:listSelector="#drawable/selector_clickable_item_bg_inverse">
<ImageView
android:id="#+id/fragment_poi_list_item_image"
android:layout_width="match_parent"
android:layout_height="#dimen/fragment_poi_list_recycler_item_size"
android:adjustViewBounds="true"
android:scaleType="centerCrop" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="#dimen/fragment_poi_list_recycler_item_panel_height"
android:layout_alignParentBottom="true"
android:gravity="center_vertical"
android:orientation="vertical"
android:paddingLeft="#dimen/global_spacing_xs"
android:paddingRight="#dimen/global_spacing_xxs"
android:background="#color/fragment_poi_list_recycler_item_panel_bg">
<TextView
android:id="#+id/fragment_poi_list_item_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="#style/TextAppearance.CityGuide.Body1.Inverse"
android:fontFamily="sans-serif"
android:maxLines="2"
android:ellipsize="end" />
<TextView
android:id="#+id/fragment_poi_list_item_distance"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/ic_grid_distance"
android:drawablePadding="#dimen/fragment_poi_list_recycler_item_icon_padding"
android:textAppearance="#style/TextAppearance.CityGuide.Body1.Inverse"
android:fontFamily="sans-serif"
android:maxLines="1"
android:ellipsize="end" />
</LinearLayout>
I was thinking if I could add an android:background="First Image" and make my Image view center but leaving some space on the edges for the background to be shown.
Would have posted 2 more images showing how the app is and how it should look, but the site won't let me post more than 2 links cause my reputation is lower than 10 -_-
Thanks in advance for the help!!!
Do it like this:
<com.inthessaloniki.cityguide.view.SelectorRelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/fragment_poi_list_item"
android:layout_width="match_parent"
android:layout_height="#dimen/fragment_poi_list_recycler_item_size"
android:minHeight="#dimen/fragment_poi_list_recycler_item_size"
android:listSelector="#drawable/selector_clickable_item_bg_inverse">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background_image"
tools:context=".MainActivity">
<ImageView
android:id="#+id/view"
android:layout_margin="5dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/foreground_image" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="#dimen/fragment_poi_list_recycler_item_panel_height"
android:layout_alignParentBottom="true"
android:gravity="center_vertical"
android:orientation="vertical"
android:paddingLeft="#dimen/global_spacing_xs"
android:paddingRight="#dimen/global_spacing_xxs"
android:background="#color/fragment_poi_list_recycler_item_panel_bg">
<TextView
android:id="#+id/fragment_poi_list_item_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="#style/TextAppearance.CityGuide.Body1.Inverse"
android:fontFamily="sans-serif"
android:maxLines="2"
android:ellipsize="end" />
<TextView
android:id="#+id/fragment_poi_list_item_distance"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/ic_grid_distance"
android:drawablePadding="#dimen/fragment_poi_list_recycler_item_icon_padding"
android:textAppearance="#style/TextAppearance.CityGuide.Body1.Inverse"
android:fontFamily="sans-serif"
android:maxLines="1"
android:ellipsize="end" />
</LinearLayout>
hope I got it clear, you could simply use two layout and adjust margin for the small one.
put your images as RelativeLayout background or use ImageView in layouts
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="25dp"></RelativeLayout>
</RelativeLayout>
I'm trying to set recyclerview item xml with google guidelines, and when i see preview in android studio - thats OK, actually margins alright. But when I'm starting app on real device (htc one s - 4.1.1 api 16) there are additional margins, which i have no idea to delete. Help me please
There are xml of recycler item:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="88dp"
android:id="#+id/Item"
android:clickable="true"
android:focusable="true"
android:background="?android:attr/selectableItemBackground"
>
<TextView
android:id="#+id/tv_recycler_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="blah"
android:textSize="16sp"
android:textStyle="bold"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="blah"
android:textSize="14sp"
android:id="#+id/textView2" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="13:00 - 14:00 14.03.2016"
android:textSize="14sp"
android:id="#+id/textView3" />
There are code from layout:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".fragments.FragmentTask">
<android.support.v7.widget.RecyclerView
android:id="#+id/my_recycler_view"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
minsdk of my app - 11
I've delete all margins and paddings from there, but problem not solved - phantom magrins exists
Whats wrong?
I cannot get my LinearLayout to "match_parent" properly. As you can see on the screenshot, the white space at the bottom should not be. If I try to apply this background color directly to the style i get a weird result where every view on the Card itself is filled with the background color.
It worked before I implemented FadingActionBar:
My Layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
style="#style/AppBaseThemeCardBG"
android:padding="#dimen/activity_standard_padding"
android:orientation="vertical">
<LinearLayout
android:id="#+id/eventCard"
style="#style/nowCardStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.mikebdev.douala.widget.RobotoTextView
android:id="#+id/eventDate"
android:textColor="#color/gray"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:typeface="roboto_condensed_light"
android:textSize="#dimen/textSizeNormal" />
<com.mikebdev.douala.widget.RobotoTextView
android:id="#+id/eventHead"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="2"
app:typeface="roboto_condensed_light"
android:textSize="#dimen/textSizeVeryLarge" />
<com.mikebdev.douala.widget.RobotoTextView
android:id="#+id/eventBody"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:typeface="roboto_condensed_light" />
</LinearLayout>
<LinearLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
</LinearLayout>
That's definitely an issue in the library, I never tested it with content that didn't fill the entire viewport.
I've just pushed to Maven Central a new version (3.1.2) of the library that should solve the issue, please let me know how it works for you.