I've tried virtually every solution out there for soft keyboard covering part of the view when pops up, on further investigation I found that it's not the keyboard but the suggestions strip that's covering the layout.
But disabling the suggestion strip from the settings of the keyboard seems the only solution.
I've tried some hacks which add padding at runtime when the keyboard pops up but none seems to work.
This screenshot will explain it better
The below code snippet is from my BottomSheetDialog:
<?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:id="#+id/design_bottom_sheet"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/feedback_text"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:background="#drawable/recognition_text_box_border_drawable"
android:gravity="start"
android:hint="#string/manager_recognition_edit_text_hint"
android:importantForAutofill="no"
android:inputType="textMultiLine|textCapSentences"
android:maxLength="200"
android:maxLines="24"
android:overScrollMode="always"
android:padding="8dp"
android:scrollbarStyle="insideInset"
android:scrollbars="vertical"
android:textColor="#android:color/black"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.appcompat.widget.AppCompatImageView
android:id="#+id/award_badge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="#id/feedback_text"
app:layout_constraintEnd_toEndOf="#id/feedback_text"
app:srcCompat="#drawable/trophy_golden" />
<include
android:id="#+id/award_badge_item"
layout="#layout/award_badge_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="#id/feedback_text"
app:layout_constraintStart_toStartOf="#id/feedback_text" />
<LinearLayout
android:id="#+id/buttons_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:orientation="horizontal"
android:weightSum="3"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/feedback_text">
<Button
android:id="#+id/cancel_recognition"
style="#style/Widget.AppCompat.Button"
android:layout_width="0dp"
android:layout_height="#dimen/medium_button_height"
android:layout_margin="4dp"
android:layout_weight="1"
android:text="#android:string/cancel" />
<Button
android:id="#+id/send_recognition"
style="#style/Widget.AppCompat.Button.Colored"
android:layout_width="0dp"
android:layout_height="#dimen/medium_button_height"
android:layout_margin="4dp"
android:layout_weight="2"
android:text="#string/send_recognition" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
add this line in your manifest activity tag where you are opening keyboard
android:windowSoftInputMode="stateHidden|adjustResize"
Related
I am using Fragment in my app. I try to put a Button top of layout but it does not go to top of the layout.
This is my xml of Fragment :
<?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=".ui.home.HomeFragment">
<Button
android:id="#+id/zirai"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="ZİRAİ"
android:textColor="#color/white"
android:textSize="20sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/döviz"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:text="DÖVİZ"
android:textColor="#color/white"
android:textSize="20sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/text_home"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="290dp"
android:layout_marginEnd="8dp"
android:textAlignment="center"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
it looks like this :
I need to put that two button top of the layout
How I can solve this issue
Thanks
You probably have a padding or margin attribute in your activity's xml file. Find;
android:paddingTop="?attr/actionBarSize"
or
android:marginTop="?attr/actionBarSize"
and remove them.
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>
Everything I've read online says to not use match_parent in the Constraint View for the height and width properties because it can't be used and won't work. I have used a constraint layout in a few projects now where I do use match_parent and it does work. Was there an update that I haven't noticed to where it is now able to be used? If not, how come it is working in my situations while it seems it doesn't work at all for other people?
Example 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="wrap_content"
android:background="#f9d1ff">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/preview"
android:layout_marginLeft="4dp"
android:text="Last Entry:"
android:textSize="12dp"
app:layout_constraintTop_toTopOf="#id/saveButton"
app:layout_constraintStart_toStartOf="parent"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="#id/clearButton"
android:id="#+id/dataText"
android:textSize="16dp"
android:layout_marginLeft="8dp"
android:text=""
android:textStyle="bold"
/>
<Button
android:layout_width="75dp"
android:layout_height="30dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="#+id/clearButton"
android:id="#+id/saveButton"
android:text="Save"
android:textSize="12dp"
android:layout_margin="8dp"
android:background="#drawable/buttonscreen"
android:padding="6dp"/>
<Button
android:layout_width="75dp"
android:layout_height="30dp"
android:gravity="center"
android:padding="6dp"
android:layout_gravity="center_horizontal"
android:layout_margin="8dp"
android:text="Clear All"
android:id="#+id/clearButton"
android:textSize="12dp"
app:layout_constraintTop_toBottomOf="#+id/saveButton"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="#+id/saveButton"
app:layout_constraintEnd_toEndOf="#id/saveButton"
android:background="#drawable/buttonscreen"/>
</androidx.constraintlayout.widget.ConstraintLayout>
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
Try this constraints for which view you want to make match parent
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.
I have a problem when i try to display a listview in my fragment, it seems like there is a white border around the fragment. I also have a similar listview displayed in an activity and it matches perfectly with the borders of the screen.
I'm gonna post below the xml file and a screenshot I took of the fragment, I hope you can help me out.
<?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">
<!-- displays the loading animation while downloading the listview -->
<RelativeLayout
android:id="#+id/loadingPanel"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" >
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true" />
</RelativeLayout>
<TextView
android:id="#+id/tv_benvenuto"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="Ecco l'elenco completo dei libri a catalogo."
android:textColor="#android:color/black"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView2" />
<ListView
android:id="#+id/lv_dashboard"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/tv_benvenuto" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="Benvenuto"
android:textColor="#android:color/black"
android:textSize="30sp"
android:textStyle="bold"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:includeFontPadding="false"
android:text="#string/empty_dashboard"
android:textAlignment="center"
android:textSize="18sp"
android:visibility="gone"/>
</android.support.constraint.ConstraintLayout>
Image of my fragment problem
Your Listview is inheriting the Benvenuto Textview's margins as it's set to aling it. Put the views in a LinearLayout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="Benvenuto"
android:textColor="#android:color/black"
android:textSize="30sp"
android:textStyle="bold" />
<TextView
android:id="#+id/tv_benvenuto"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="Ecco l'elenco completo dei libri a catalogo."
android:textColor="#android:color/black"
android:textSize="18sp" />
<ListView
android:id="#+id/lv_dashboard"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
Sometimes when you set the width and height to match-constraint I've noticed that it adds some imaginary padding like this for whatever reason. It looks like this layout is pretty simple and just linearly goes from top to bottom in terms of its views. Why don't you just use a LinearLayout instead, and set the dimensions to matchparent? That should fix it, unless you need to add more stuff to this layout.