How to change scale type - java

Ive got problem with my single item activity, in my activity design everything looks good image in design tab,but when I run the app image gets bigger in app image in the app
Code for whole xml layout
<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="175dp">
<ImageView
android:id="#+id/container_org"
android:layout_width="match_parent"
android:layout_height="150dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:srcCompat="#android:drawable/screen_background_light_transparent"
app:tint="#color/grey" />
<ImageView
android:id="#+id/item_org_logo"
android:layout_width="110dp"
android:layout_height="150dp"
android:layout_marginStart="8dp"
android:scaleType="fitCenter"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.48"
app:srcCompat="#drawable/eu" />
<TextView
android:id="#+id/item_org_description"
android:layout_width="250dp"
android:layout_height="85dp"
android:layout_marginStart="8dp"
android:layout_marginTop="10dp"
android:text="#string/eu_long_desc"
app:layout_constraintStart_toEndOf="#+id/item_org_logo"
app:layout_constraintTop_toBottomOf="#+id/item_org_title" />
<TextView
android:id="#+id/item_org_title"
android:layout_width="249dp"
android:layout_height="38dp"
android:layout_marginStart="8dp"
android:layout_marginTop="4dp"
android:text="#string/eu2"
android:textColor="#color/black"
android:textStyle="bold"
app:layout_constraintStart_toEndOf="#+id/item_org_logo"
app:layout_constraintTop_toTopOf="#+id/container_org" />
</androidx.constraintlayout.widget.ConstraintLayout>

It's because of the conflict between
app:layout_constraintVertical_bias="0.48"
and explicitly declared width:
android:layout_width="110dp"
You either have to remove bias attribute or change width attribute to wrap_content or 0dp. I would recommend this edition:
<?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="175dp">
<ImageView
android:id="#+id/container_org"
android:layout_width="match_parent"
android:layout_height="150dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:srcCompat="#android:drawable/screen_background_light_transparent"
app:tint="#color/grey" />
<ImageView
android:id="#+id/item_org_logo"
android:layout_width="110dp"
android:layout_height="150dp"
android:layout_marginStart="8dp"
android:scaleType="fitCenter"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/eu" />
<TextView
android:id="#+id/item_org_description"
android:layout_width="0dp"
android:layout_height="85dp"
android:layout_marginStart="8dp"
android:layout_marginTop="10dp"
android:text="#string/eu_long_desc"
app:layout_constraintStart_toEndOf="#+id/item_org_logo"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/item_org_title" />
<TextView
android:id="#+id/item_org_title"
android:layout_width="0dp"
android:layout_height="38dp"
android:layout_marginStart="8dp"
android:layout_marginTop="4dp"
android:text="#string/eu2"
android:textColor="#color/black"
android:textStyle="bold"
app:layout_constraintStart_toEndOf="#+id/item_org_logo"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="#+id/container_org" />
</androidx.constraintlayout.widget.ConstraintLayout>

Related

FrameLayout with Recyclerview

I want to put the bottom navigation menu with my recyclerview at the bottom of the view. It is currently at the top and I need help sending it to the bottom.
This is how it look now:
This is my xml code:
<?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"
tools:context=".MainActivity">
<TextView
android:id="#+id/titleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:text="Oficinas Credenciadas"
android:textColor="#android:color/black"
android:textSize="30sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/listRecyclerView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="1dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="1dp"
android:layout_marginBottom="1dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/titleTextView" />
<FrameLayout
android:id="#+id/frame"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
app:layout_constraintTop_toBottomOf="#+id/titleTextView"
/>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:menu="#menu/botton_nav_menu"
tools:ignore="MissingConstraints" />
</androidx.constraintlayout.widget.ConstraintLayout>
Add
app:layout_constraintBottom_toBottomOf="parent"
To bottom navigation item so code will be like that
<com.google.android.material.bottomnavigation.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:menu="#menu/botton_nav_menu"
tools:ignore="MissingConstraints" />
I have made some changes and this is how it the items are positioned now.
This is how the code looks now. If this helps you, an upvote would be appreciated. Thanks
<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">
<TextView
android:id="#+id/titleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="Oficinas Credenciadas"
android:textColor="#android:color/black"
android:textSize="30sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/listRecyclerView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="1dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="1dp"
android:layout_marginBottom="1dp"
app:layout_constraintBottom_toTopOf="#+id/bottom_menu"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/titleTextView" />
<!-- NOT SURE WHY YOU HAVE THE FRAMELAYOUT AND RECYCLERVIEW OCCUPYING THE SAME SPACE BUT IF YOU INTEND TO HIDE AND SHOW THEM AT DIFFERENT TIMES, I HAVE IMPROVED THEIR CONSTRAINTS -->
<FrameLayout
android:id="#+id/frame"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
app:layout_constraintBottom_toTopOf="#+id/bottom_menu"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/titleTextView"
/>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="#menu/sample_menu"
tools:ignore="MissingConstraints" />
</androidx.constraintlayout.widget.ConstraintLayout>

Why is my RecyclerView is invisible inside ScrollView?

I have a scrollView in my xml. There's ConstraintLayout inside of it. In the ConstraintLayout is my RecyclerView. It's invisible. When I change ScrollView to ConstraintLayout everything gets back to normal. Here is my xml:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:fillViewport="true"
tools:context=".ui.fragments.ChannelAudioFragment">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ProgressBar
android:id="#+id/allChannelAudiosProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.textview.MaterialTextView
android:id="#+id/noAudiosTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:visibility="gone"
android:gravity="center|left"
android:text="No audios"
android:layout_marginTop="5dp"
android:textSize="15dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="#+id/channelAudiosRefreshSwipe"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="MissingConstraints">
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rvAllChannelAudios"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="match_parent" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
I don't get any errors in console. Why is this happening?
UPDATE
Additional info: I'm using it in ViewPager. Here it is
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".ui.fragments.ChannelFragment">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/channelBlock"
android:layout_width="match_parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_margin="30dp"
android:background="#drawable/main_background"
android:padding="20dp"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/ivChannelImage"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="#drawable/ic_person_flat"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.textview.MaterialTextView
android:id="#+id/channelName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Qewbite"
android:textColor="#color/whiteColor"
android:layout_marginTop="8dp"
android:textSize="26sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#id/ivChannelImage" />
<LinearLayout
android:id="#+id/subscriptionBlock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#id/channelName"
android:gravity="center_vertical">
<Button
android:id="#+id/subscribeButton"
android:layout_width="wrap_content"
android:textAllCaps="false"
android:layout_height="40dp"
android:textSize="12dp"
android:gravity="center"
android:background="#drawable/subscribed_background"
android:padding="0dp"
app:backgroundTint="#color/colorDark"
android:textColor="#color/whiteColor"
android:layout_marginLeft="5dp"
android:text="Unfollow" />
<ImageButton
android:id="#+id/notificationButton"
android:layout_width="40dp"
android:textAllCaps="false"
android:layout_height="40dp"
android:textSize="12dp"
android:tint="#color/whiteColor"
android:src="#drawable/ic_notification"
app:backgroundTint="#color/colorDark"
android:background="#drawable/subscribe_notification_background"
android:padding="0dp"
android:textColor="#color/whiteColor" />
</LinearLayout>
<View
android:id="#+id/headerHr"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/colorNavbarGray"
app:layout_constraintTop_toBottomOf="#id/subscriptionBlock"
android:layout_marginTop="10dp"
/>
<com.google.android.material.textview.MaterialTextView
android:id="#+id/channelSubscribers"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="10M"
android:textColor="#color/whiteColor"
android:layout_marginTop="8dp"
android:textSize="16sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="#id/channelSubscribersTitle"
app:layout_constraintEnd_toEndOf="#id/channelSubscribersTitle"
app:layout_constraintTop_toBottomOf="#id/headerHr" />
<com.google.android.material.textview.MaterialTextView
android:id="#+id/channelSubscribersTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Followers"
android:textColor="#color/colorLightGray"
android:textSize="12sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/channelSubscribers" />
<com.google.android.material.textview.MaterialTextView
android:id="#+id/channelListened"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="120M"
android:textColor="#color/whiteColor"
android:layout_marginTop="8dp"
android:textSize="16sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="#id/channelListenedTitle"
app:layout_constraintEnd_toEndOf="#id/channelListenedTitle"
app:layout_constraintTop_toBottomOf="#id/headerHr" />
<com.google.android.material.textview.MaterialTextView
android:id="#+id/channelListenedTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Auditions"
android:textColor="#color/colorLightGray"
android:textSize="12sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#id/channelListened" />
<com.google.android.material.textview.MaterialTextView
android:id="#+id/channelYear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2021"
android:textColor="#color/whiteColor"
android:layout_marginTop="8dp"
android:textSize="16sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#id/headerHr" />
<com.google.android.material.textview.MaterialTextView
android:id="#+id/channelYearTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Year"
android:textColor="#color/colorLightGray"
android:textSize="12sp"
app:layout_constraintStart_toStartOf="#id/channelYear"
app:layout_constraintEnd_toEndOf="#id/channelYear"
app:layout_constraintTop_toBottomOf="#id/channelSubscribers" />
</androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.tabs.TabLayout
android:id="#+id/tab"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabSelectedTextColor="#color/colorPrimary"
app:layout_constraintTop_toBottomOf="#id/channelBlock"
app:layout_constraintStart_toStartOf="#id/channelBlock"
app:tabRippleColor="#color/colorGray"
android:layout_marginTop="8dp" />
<androidx.viewpager2.widget.ViewPager2
android:id="#+id/channelViewPager"
android:layout_height="wrap_content"
android:layout_width="match_parent"
app:layout_constraintTop_toBottomOf="#id/tab"
app:layout_constraintStart_toStartOf="#id/tab" />
</androidx.constraintlayout.widget.ConstraintLayout>
Most probably that is because you put more than 1 view inside ScrollView , ScrollView expects 1 view from you. If you want to put more than one consider using a viewGroup view and put your views inside it. For Instance , you can use a vertical LinearLayout to wrap the Views you used. Also , consider using NestedScrollView instead.
Try this one
<?xml version="1.0" encoding="utf-8"?>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="#+id/swipe_refresh"
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">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="0dp"
>
<ProgressBar
android:id="#+id/allChannelAudiosProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.textview.MaterialTextView
android:id="#+id/noAudiosTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:visibility="gone"
android:gravity="center|left"
android:text="No audios"
android:layout_marginTop="5dp"
android:textSize="15dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/rvAllChannelAudios"
tools:listitem="#layout/event_near_items"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:itemCount="10"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
swipe_refresh.setOnRefreshListener {
swipe_refresh.isRefreshing = false
// refresh the list here
}
Why not try a nested scroll view.

Why Fragment/Activity layout looks bad when changing device language to RTL languge?

I built an application (for practice Android), and i use start, end in order to support both LTR and RTL languages. I also set android:supportsRtl="true" in manifest file.
When device is set to LTR language all text looks great, and alignment great to the left. But, when changing device language to RTL language, all text seems bad and isn't alignment to the right (maybe some of the TextView are alignment and some aren't). In addition it seems that the Spinner view is totally Wrong. I have attached two screen shot (for both languages). I'm asking for your help, because i don't understand what i'm doing wrong.
Also attached 3 code snipping (one for all the layout, the second for the item inside the RecyclerView and the third the item for the Spinner:
<?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="#color/backgroundColor">
<Spinner
android:id="#+id/spinner"
android:layout_width="0dp"
android:layout_height="48dp"
android:layout_marginStart="3dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="3dp"
android:background="#null"
android:dropDownWidth="120dp"
android:dropDownVerticalOffset="96dp"
android:gravity="center"
android:visibility="invisible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.example.currencyconvertor.MultiButton
android:id="#+id/multiButton"
android:layout_width="300dp"
android:layout_height="50dp"
android:layout_marginTop="15dp"
app:activeButtonIndex="0"
app:backgroundSelector="#drawable/multi_button_background_selector"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/spinner"
app:numOfButtons="2"
app:reversedOrder="false"
android:visibility="gone"
app:textColorSelector="#drawable/multi_button_text_color" />
<TextView
android:id="#+id/textView1"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_marginStart="3dp"
android:layout_marginTop="22dp"
android:textColor="#color/titleTextColor"
android:textSize="13sp"
app:layout_constraintEnd_toStartOf="#id/textView2"
app:layout_constraintHorizontal_chainStyle="spread_inside"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/multiButton"
tools:text="TextView1" />
<TextView
android:id="#+id/textView2"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:text="Symbol"
android:textColor="#color/titleTextColor"
android:textSize="13sp"
app:layout_constraintEnd_toStartOf="#id/textView3"
app:layout_constraintStart_toEndOf="#id/textView1"
app:layout_constraintTop_toTopOf="#id/textView1"
tools:text="TextView2" />
<TextView
android:id="#+id/textView3"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:textColor="#color/titleTextColor"
android:textSize="13sp"
app:layout_constraintEnd_toStartOf="#id/textView4"
app:layout_constraintStart_toEndOf="#id/textView2"
app:layout_constraintTop_toTopOf="#id/textView1"
app:layout_goneMarginEnd="3dp"
tools:text="TextView3" />
<TextView
android:id="#+id/textView4"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:layout_marginEnd="3dp"
android:textColor="#color/titleTextColor"
android:textSize="13sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#id/textView3"
app:layout_constraintTop_toTopOf="#id/textView1"
android:visibility="gone"
tools:text="TextView4" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="3dp"
android:layout_marginTop="7dp"
android:layout_marginEnd="3dp"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/textView1"
tools:listitem="#layout/relative_currency_rate_row" />
<ProgressBar
android:id="#+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxHeight="200dp"
android:maxWidth="200dp"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/textView1" />
</androidx.constraintlayout.widget.ConstraintLayout>
Code for RecyclerView item:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginBottom="1dp"
android:background="#color/rowColor"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/container"
android:layout_width="80dp"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="#id/targetCountryTextView"
app:layout_constraintHorizontal_chainStyle="spread_inside"
tools:ignore="MissingConstraints">
<ImageView android:id="#+id/countryFlagImageView"
android:layout_width="32dp"
android:layout_height="32dp"
app:layout_constraintStart_toStartOf="#id/container"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:src="#drawable/ic_launcher_background"
android:paddingEnd="4dp" />
<TextView
android:id="#+id/currencyTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toEndOf="#id/countryFlagImageView"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginStart="2dp"
android:layout_marginTop="13dp"
android:layout_marginBottom="12dp"
android:textSize="13sp"
android:text="USA"
android:textColor="#color/currencyRowTextColor"/>
</androidx.constraintlayout.widget.ConstraintLayout>
<TextView
android:id="#+id/targetCountryTextView"
android:layout_width="80dp"
android:layout_height="wrap_content"
app:layout_constraintStart_toEndOf="#id/container"
app:layout_constraintEnd_toStartOf="#id/rateTextView"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginTop="13dp"
android:layout_marginBottom="12dp"
android:textSize="13sp"
android:text="Dollar"
android:textColor="#color/currencyRowTextColor" />
<TextView
android:id="#+id/rateTextView"
android:layout_width="80dp"
android:layout_height="wrap_content"
app:layout_constraintStart_toEndOf="#id/targetCountryTextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginTop="13dp"
android:layout_marginBottom="12dp"
android:textSize="13sp"
android:text="0.417"
android:textColor="#color/currencyRowTextColor" />
</androidx.constraintlayout.widget.ConstraintLayout>
Code for Spinner item:
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/rowColor">
<ImageView
android:id="#+id/flagImageView"
android:layout_width="48dp"
android:layout_height="48dp"
app:layout_constraintEnd_toStartOf="#+id/countryTextView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:padding="4dp"
app:srcCompat="#drawable/default_glag"
android:textColor="#color/currencyRowTextColor"/>
<TextView
android:id="#+id/countryTextView"
android:layout_width="wrap_content"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="#id/flagImageView"
android:layout_marginStart="30dp"
android:gravity="center"
android:textSize="17sp"
android:textColor="#color/currencyRowTextColor"/>
<TextView
android:id="#+id/currencyTextView"
android:layout_width="wrap_content"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="#id/countryTextView"
android:layout_marginStart="5dp"
android:gravity="center"
android:text="countryCurrencyTextView"
android:textSize="17sp"
android:textColor="#color/currencyRowTextColor"/>
<ImageView
android:layout_width="48dp"
android:layout_height="48dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="4dp"
android:src="#mipmap/ic_arrow_drop_down"/>
</androidx.constraintlayout.widget.ConstraintLayout>[![enter image description here][1]][1]
disable supports RTL on your manifest file:
<application
...
android:supportsRtl="false">
I hope to be useful ;)

Recyclerview very slow to load

I have a recycler view in an Activity where sometimes I show a lot of elements. The problem is that when the number of elements is very high the recycler view needs some seconds to render the elements and it's frustrating. I wonder why.
My code:
<android.support.v4.widget.NestedScrollView 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:id="#+id/_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="cct.appload.fragments.FileManagerFragment">
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="true">
<Spinner
android:id="#+id/_order_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:contentDescription="#string/back"
android:src="#drawable/ic_arrow_back_black_24dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
<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_marginBottom="8dp"
android:layout_marginTop="8dp"
android:elevation="1dp"
card_view:cardCornerRadius="0dp"
card_view:cardElevation="2dp">
<TextView
android:id="#+id/_msg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:gravity="center"
android:visibility="invisible" />
<ProgressBar
android:id="#+id/manager_progress_bar"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:progressTint="#color/colorAccent"
android:visibility="invisible" />
<android.support.v7.widget.RecyclerView
android:id="#+id/_recycler_view"
android:layout_width="match_parent"
android:nestedScrollingEnabled="false"
android:layout_height="wrap_content"
android:paddingStart="8dp"
android:paddingEnd="8dp"
android:scrollbars="vertical" />
</android.support.v7.widget.CardView>
</LinearLayout>
My single item:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/_container"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/_icon"
android:layout_width="44dp"
android:layout_height="44dp"
android:layout_marginBottom="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:background="#drawable/circle_background"
android:padding="10dp"
android:tint="#color/white"
app:layout_constraintBottom_toTopOf="#+id/_separator"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/ic_folder_black_24dp" />
<TextView
android:id="#+id/_titolo"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:ellipsize="end"
android:lines="1"
android:maxLines="1"
android:text="Titolo"
android:textAppearance="#android:style/TextAppearance.Material.Body2"
app:layout_constraintEnd_toStartOf="#+id/_menu"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="#+id/_icon"
app:layout_constraintTop_toTopOf="#+id/_icon" />
<TextView
android:id="#+id/_dimensione"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:padding="0dp"
android:text="dimensione"
android:ellipsize="end"
android:lines="1"
app:layout_constraintBottom_toBottomOf="#+id/_icon"
app:layout_constraintEnd_toStartOf="#+id/_menu"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="#+id/_icon"
app:layout_constraintTop_toBottomOf="#+id/_titolo" />
<ImageButton
android:id="#+id/_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:background="#android:color/transparent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/ic_more_vert_black_24dp" />
<View
android:id="#+id/_separator"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="0dp"
android:background="#color/lightGrey"
app:layout_constraintBottom_toBottomOf="parent" />
</android.support.constraint.ConstraintLayout>
In order to update the elements I simply change the list of them and then I notify that to the recycler view.
I think the best solution is not loading all data, just using lazy-loading
Refer here
I had a problem with a very small amount of items. I'm using Room Dao.
The reason why RecycleView ran so slow was the fact that photos that l used were large in size. So be careful about that.

How to modify chain length in constraint layout?

Here is my code
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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="#color/nav_and_action_bar_color"
>
<ImageView
android:id="#+id/some_person"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="#drawable/some_person"
app:layout_constraintBottom_toTopOf="#+id/et_username"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="#+id/et_username"
android:layout_width="#dimen/login_page_text_fields_width"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#android:color/white"
android:hint="#string/email_hint"
android:padding="10dp"
app:layout_constraintBottom_toTopOf="#+id/et_password"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/some_person" />
<EditText
android:id="#+id/et_password"
android:layout_width="#dimen/login_page_text_fields_width"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#android:color/white"
android:hint="#string/password_hint"
android:inputType="textPassword"
android:padding="10dp"
app:layout_constraintBottom_toTopOf="#+id/login_button"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#id/et_username" />
<Button
android:id="#+id/login_button"
android:layout_width="#dimen/login_button_width"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#color/colorAccent"
android:elevation="5dp"
android:onClick="clickedOnLogin"
android:text="#string/login_button"
android:textColor="#android:color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#id/et_password" />
</android.support.constraint.ConstraintLayout>
and i seem to be getting this as a result
How do i bring the elements together? I want them to be close together.
You need to define variable for every view, where you want to apply chaining logic. Pick just one:
app:layout_constraintVertical_chainStyle="packed"
app:layout_constraintVertical_chainStyle="spread"
app:layout_constraintVertical_chainStyle="spread_inside"
Use below code to get the desired layout.
Changes in the below code of yours is "app:layout_constraintVertical_chainStyle="packed".
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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="#color/nav_and_action_bar_color">
<ImageView
android:id="#+id/some_person"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="#drawable/some_person"
app:layout_constraintBottom_toTopOf="#+id/et_username"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed" />
<EditText
android:id="#+id/et_username"
android:layout_width="#dimen/login_page_text_fields_width"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#android:color/white"
android:hint="#string/email_hint"
android:padding="10dp"
app:layout_constraintBottom_toTopOf="#+id/et_password"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#+id/some_person" />
<EditText
android:id="#+id/et_password"
android:layout_width="#dimen/login_page_text_fields_width"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#android:color/white"
android:hint="#string/password_hint"
android:inputType="textPassword"
android:padding="10dp"
app:layout_constraintBottom_toTopOf="#+id/login_button"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#id/et_username" />
<Button
android:id="#+id/login_button"
android:layout_width="#dimen/login_button_width"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#color/colorAccent"
android:elevation="5dp"
android:onClick="clickedOnLogin"
android:text="#string/login_button"
android:textColor="#android:color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="#id/et_password" />
</android.support.constraint.ConstraintLayout>
I managed to bring the elements close together. According to this page
Chains are controlled by attributes set on the first element of the chain (the "head" of the chain):
So i added this to <ImageView> tag
app:layout_constraintVertical_chainStyle="packed"
and since i did not want it to be at the center vertically i also added this to the same tag
app:layout_constraintVertical_bias="0.4"
So that it is not at the center but is slightly biased towards to the top.

Categories