Android chat listview not scrolling totally - java

I have a ListView of a chat that is not scrolling till the end of all the messages. I can't figure out why this is happening. If I send a new message and the length of all the messages in the chat is more than a page so i nedd to scroll over to see the message i succeed to scroll but not enogh to see all the messages.
My Layout XML code here :
<android.support.constraint.ConstraintLayout xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#drawable/cool_background3">
<ListView
android:layout_width="wrap_content"
android:id="#+id/messages_view"
android:layout_weight="1"
android:divider="#fff"
android:layout_height="0dp"
tools:layout_editor_absoluteX="8dp"
app:layout_constraintTop_toBottomOf="#+id/topBar" />
<LinearLayout
android:id="#+id/layout_chatbox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:minHeight="48dp"
android:background="#ffffff"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent">
<EditText
android:id="#+id/edittext_chatbox"
android:hint="Enter message"
android:background="#android:color/transparent"
android:layout_gravity="center"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:maxLines="6"
/>
<Button
android:id="#+id/button_chatbox_send"
android:text="send"
android:textSize="14dp"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:layout_width="64dp"
android:layout_height="48dp"
android:gravity="center"
android:textColor="#color/myColor"
android:layout_gravity="bottom"
android:onClick="sendMessage"/>
</LinearLayout>
<RelativeLayout
android:id="#+id/topBar"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:minHeight="50dp"
android:background="#color/white"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
tools:layout_editor_absoluteY="0dp">
<TextView
android:id="#+id/name_of_user"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tomnaor"
android:textColor="#color/myColor"
android:textStyle="bold"
android:textSize="20dp"
android:layout_marginStart="30dp"
android:layout_centerVertical="true"
/>
<TextView
android:id="#+id/emotion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Happy Chat"
android:textColor="#939393"
android:textSize="14dp"
android:layout_toEndOf="#+id/name_of_user"
android:layout_marginStart="4dp"
android:layout_below="#+id/name_of_user"/>
</RelativeLayout>

Add this in your ListView xml:
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll"
For reference:
stack from bottom
transcript mode

you are not given proper constraint to your ListView.
You may try this way :
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#drawable/cool_background3">
<ListView
android:id="#+id/messages_view"
android:layout_width="0dp"
android:layout_height="0dp"
android:divider="#fff"
app:layout_constraintBottom_toTopOf="#+id/layout_chatbox"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/topBar" />
<LinearLayout
android:id="#+id/layout_chatbox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:minHeight="48dp"
android:background="#ffffff"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent">
<EditText
android:id="#+id/edittext_chatbox"
android:hint="Enter message"
android:background="#android:color/transparent"
android:layout_gravity="center"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:maxLines="6"
/>
<Button
android:id="#+id/button_chatbox_send"
android:text="send"
android:textSize="14dp"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:layout_width="64dp"
android:layout_height="48dp"
android:gravity="center"
android:textColor="#color/myColor"
android:layout_gravity="bottom"
android:onClick="sendMessage"/>
</LinearLayout>
<RelativeLayout
android:id="#+id/topBar"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:minHeight="50dp"
android:background="#color/white"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
tools:layout_editor_absoluteY="0dp">
<TextView
android:id="#+id/name_of_user"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tomnaor"
android:textColor="#color/myColor"
android:textStyle="bold"
android:textSize="20dp"
android:layout_marginStart="30dp"
android:layout_centerVertical="true"
/>
<TextView
android:id="#+id/emotion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Happy Chat"
android:textColor="#939393"
android:textSize="14dp"
android:layout_toEndOf="#+id/name_of_user"
android:layout_marginStart="4dp"
android:layout_below="#+id/name_of_user"/>
</RelativeLayout>
</android.support.constraint.ConstraintLayout>

Related

How can I make a buttons from a Layout in Android Studio

I have buttons what I made with "LinearLayout" but when I want to made them clickable and so that it goes to another activity. I understand, that I need to change from "LinearLayout" to "ImageButton" because I want to make a beautiful app [what I want it looks like][1], but when I launch it, it stops working. What can I do to repair that? Thank you in advance for your help and sorry for my bad english. :(
<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/colorBackground"
tools:context=".MainActivity">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/layoutHeader"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/header_background"
android:padding="20dp"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="#+id/textHello"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:text="#string/hello"
android:textColor="#color/colorWhite"
android:textSize="25sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="TextContrastCheck" />
<TextView
android:id="#+id/textUsername"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:text="#string/vassili"
android:textColor="#color/colorWhite"
android:textSize="25sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="#id/textHello"
tools:ignore="TextContrastCheck" />
<ImageView
android:id="#+id/imageMenu"
android:layout_width="30dp"
android:layout_height="30dp"
android:contentDescription="#string/app_name"
android:src="#drawable/ic_menu"
app:layout_constraintBottom_toBottomOf="#id/textHello"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="#id/textHello"
app:tint="#color/colorWhite"
tools:ignore="ImageContrastCheck" />
</androidx.constraintlayout.widget.ConstraintLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:overScrollMode="never"
android:scrollbars="none"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="#id/layoutHeader"
app:layout_constraintVertical_bias="0.0"
tools:layout_editor_absoluteX="-96dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/layoutGoal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="22dp"
android:background="#drawable/white_background_icons"
android:gravity="center"
android:orientation="vertical"
android:padding="15dp"
app:layout_constraintDimensionRatio="H, 1:1"
app:layout_constraintEnd_toStartOf="#id/layoutTraining"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="UseCompoundDrawables">
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_margin="8dp"
android:contentDescription="#string/app_name"
android:padding="8dp"
android:src="#drawable/notepad" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/goals"
android:textColor="#color/colorAccent"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="#+id/layoutTraining"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="22dp"
android:background="#drawable/white_background_icons"
android:gravity="center"
android:orientation="vertical"
android:padding="15dp"
app:layout_constraintDimensionRatio="H, 1:1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#id/layoutGoal"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="UseCompoundDrawables">
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_margin="8dp"
android:contentDescription="#string/app_name"
android:padding="8dp"
android:src="#drawable/dumbbell" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/Trainings"
android:textColor="#color/colorAccent"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="#+id/layoutWater"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="22dp"
android:background="#drawable/white_background_icons"
android:gravity="center"
android:orientation="vertical"
android:padding="15dp"
app:layout_constraintDimensionRatio="H, 1:1"
app:layout_constraintEnd_toStartOf="#id/layoutTraining"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/layoutGoal"
tools:ignore="UseCompoundDrawables">
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_margin="8dp"
android:contentDescription="#string/app_name"
android:padding="8dp"
android:src="#drawable/bottle" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/Water"
android:textColor="#color/colorAccent"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="#+id/layoutStepCounter"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="22dp"
android:background="#drawable/white_background_icons"
android:gravity="center"
android:orientation="vertical"
android:padding="15dp"
app:layout_constraintDimensionRatio="H, 1:1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#id/layoutGoal"
app:layout_constraintTop_toBottomOf="#id/layoutTraining"
tools:ignore="UseCompoundDrawables">
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_margin="8dp"
android:contentDescription="#string/app_name"
android:padding="8dp"
android:src="#drawable/walk" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="#string/step_counter"
android:textColor="#color/colorAccent"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
[1]: https://i.stack.imgur.com/WdW6v.png
May you need to change constraintlayout to LinearLayout and if you want click be on image add id to imageview
For this type of layout you need to make your LinearLayout clickable
For example:
LinearLayout linearLayoutGoals;
then in you onCreate do findViewById and set its clickListener
linearLayoutGoals = findViewById(R.id.layoutGoal);
linearLayoutGoals.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//DO YOUR CODE
}
});

How to fill the entire screen in a RecyclerView

I have a problem filling the entire screen in a reclycle view.
This is my xml code of the cardview and my view where the reclyclerview is:
CardView:
This is how it looks in the Ide Android studio:
Layout where the Reclycler view is:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/textAmount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:padding="4dp"
android:text="30"
android:textSize="30sp" />
<TextView
android:id="#+id/textIdPerson"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:padding="4dp"
android:text="30"
android:textSize="30sp" />
<TextView
android:id="#+id/textId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:padding="4dp"
android:text="30"
android:textSize="30sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="4dp">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
app:cardCornerRadius="4dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/textAmount"
android:padding="8dp"
android:text="ID"
android:textSize="30sp"
android:layout_weight="1"
android:gravity="center"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/textIdPerson"
android:padding="8dp"
android:layout_weight="1"
android:text="UserId"
android:textSize="30sp"
android:gravity="center"/>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/textId"
android:padding="8dp"
android:textSize="30sp"
android:layout_weight="1"
android:text="Amount"
android:gravity="center"/>
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.recyclerview.widget.RecyclerView
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:id="#+id/recycler_view"
android:nestedScrollingEnabled="false"
tools:listitem="#layout/list_row_main"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_alignParentBottom="true">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="atras"
android:onClick="#{viewmodel::back}"
android:layout_weight="1"
android:layout_marginRight="4dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Siguiente"
android:onClick="#{viewmodel::next}"
android:layout_weight="1"/>
</LinearLayout>
Image:
enter image description here
But when I start the application on the device it looks like this
enter image description here
Your activity_main.xml(or any layout that hosts recyclerview) should look like this.
<androidx.appcompat.widget.LinearLayoutCompat 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:orientation="vertical"
>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_marginStart="5dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="5dp"
app:cardCornerRadius="5dp"
app:cardElevation="8dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="center"
android:gravity="center_vertical|center"
android:orientation="horizontal">
<TextView
android:id="#+id/textAmount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:padding="4dp"
android:text="Amount"
android:textSize="30sp" />
<TextView
android:id="#+id/textIdPerson"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:padding="4dp"
android:text="UserID"
android:textSize="30sp" />
<TextView
android:id="#+id/textId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:padding="4dp"
android:text="Id"
android:textSize="30sp" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_marginBottom="8dp"
android:layout_weight="2"
android:nestedScrollingEnabled="false"
tools:listitem="#layout/list_item" />
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/btnAtras"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:layout_marginBottom="5dp"
android:layout_weight="1"
android:text="ATRAS"
/>
<Button
android:id="#+id/btnSignature"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:layout_marginBottom="5dp"
android:layout_weight="1"
android:text="Signature" />
</androidx.appcompat.widget.LinearLayoutCompat>
</androidx.appcompat.widget.LinearLayoutCompat>
And list_item.xml layout should be something like below:
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.cardview.widget.CardView
android:layout_width="0dp"
android:layout_height="60dp"
app:cardCornerRadius="5dp"
app:cardElevation="8dp"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
app:cardUseCompatPadding="false"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_gravity="center"
android:gravity="center|center_vertical"
>
<TextView
android:gravity="center"
android:id="#+id/textAmount"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_width="match_parent"
android:padding="8dp"
android:text="Amount"
android:textSize="30sp" />
<TextView
android:gravity="center"
android:id="#+id/textIdPerson"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_width="match_parent"
android:padding="8dp"
android:text="UserId"
android:textSize="30sp" />
<TextView
android:gravity="center"
android:id="#+id/textId"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_width="match_parent"
android:padding="8dp"
android:text="Id"
android:textSize="30sp" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>
Check your adapter class, Layout you designed for adapter class should have width match parent and three different textviews with equal width to hold values.
Make sure the RecyclerView has layout_width also set to match_parent.

Scrollview not scrolling the entire screen

Currently, my scrollview could only scroll the bottom part of the screen. However though, I want the scrollview to be able to scroll the entire screen like how you would be able to normally and smoothly scroll an entire screen within an app. But i can't figure out what went wrong where for me as only i could scroll the bottom portion of the screen.Could anyone advise me on how? Thanks
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:orientation="vertical"
tools:context=".SettingsFragment">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:animateLayoutChanges="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/rellay1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/grad"
android:paddingBottom="20dp">
<RelativeLayout
android:id="#+id/imgUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:background="#drawable/circle_border">
<ImageView
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_margin="9dp"
android:adjustViewBounds="true"
android:background="#drawable/circle"
android:padding="3dp"
android:scaleType="centerInside"
android:src="#drawable/ic_user" />
</RelativeLayout>
<TextView
android:id="#+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/imgUser"
android:layout_centerHorizontal="true"
android:layout_marginTop="15sp"
android:fontFamily="sans-serif-light"
android:text="Joey Tribbiani"
android:textColor="#color/white"
android:textSize="32sp" />
<TextView
android:id="#+id/tv_address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tv_name"
android:layout_centerHorizontal="true"
android:fontFamily="sans-serif"
android:text="new york, usa"
android:textAllCaps="true"
android:textColor="#color/address"
android:textSize="14sp" />
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#color/followersBg"
android:gravity="center"
android:layout_marginTop="250dp"
android:id="#+id/Rl1"
android:paddingBottom="5dp"
android:paddingTop="5dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="80">
<TextView
android:id="#+id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:layout_marginLeft="15dp"
android:layout_marginTop="15dp"
android:text="My Order"
android:textColor="#color/white"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:layout_conversion_absoluteHeight="19dp"
tools:layout_conversion_absoluteWidth="58dp" />
<ImageView
android:id="#+id/ivWallet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="35dp"
android:layout_marginLeft="35dp"
android:layout_marginTop="45dp"
android:src="#drawable/ic_baseline_account_balance_wallet_24"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:layout_conversion_absoluteHeight="24dp"
tools:layout_conversion_absoluteWidth="24dp" />
<TextView
android:id="#+id/tvTitleToBePaid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="17dp"
android:layout_marginLeft="17dp"
android:layout_marginTop="8dp"
android:text="To be Paid"
android:textColor="#color/white"
android:textSize="13dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/ivWallet"
tools:layout_conversion_absoluteHeight="19dp"
tools:layout_conversion_absoluteWidth="66dp" />
<ImageView
android:id="#+id/ivBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="75dp"
android:layout_marginLeft="75dp"
android:layout_marginTop="45dp"
android:src="#drawable/ic_baseline_tobedelivered_24"
app:layout_constraintStart_toEndOf="#+id/ivWallet"
app:layout_constraintTop_toTopOf="parent"
tools:layout_conversion_absoluteHeight="24dp"
tools:layout_conversion_absoluteWidth="24dp" />
<TextView
android:id="#+id/tvTobeDelivered"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginLeft="24dp"
android:layout_marginTop="8dp"
android:text="To be Delivered"
android:textColor="#color/white"
android:textSize="13dp"
app:layout_constraintStart_toEndOf="#+id/tvTitleToBePaid"
app:layout_constraintTop_toBottomOf="#+id/ivBox" />
<ImageView
android:id="#+id/ivBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="76dp"
android:layout_marginLeft="76dp"
android:layout_marginTop="44dp"
android:src="#drawable/ic_baseline_tobereceived_24"
app:layout_constraintStart_toEndOf="#+id/ivBox"
app:layout_constraintTop_toTopOf="parent"
tools:layout_conversion_absoluteHeight="24dp"
tools:layout_conversion_absoluteWidth="24dp" />
<TextView
android:id="#+id/tvTobeReceived"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="8dp"
android:text="To be Received"
android:textColor="#color/white"
android:textSize="13dp"
app:layout_constraintStart_toEndOf="#+id/tvTobeDelivered"
app:layout_constraintTop_toBottomOf="#+id/ivBox2" />
<ImageView
android:id="#+id/ivThumbs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="90dp"
android:layout_marginLeft="90dp"
android:layout_marginTop="45dp"
android:layout_marginEnd="35dp"
android:layout_marginRight="35dp"
android:src="#drawable/ic_baseline_tobeevaluated_24"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/ivBox2"
app:layout_constraintTop_toTopOf="parent"
tools:layout_conversion_absoluteHeight="24dp"
tools:layout_conversion_absoluteWidth="24dp" />
<TextView
android:id="#+id/tvTobeEvaluated"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="18dp"
android:layout_marginLeft="18dp"
android:layout_marginTop="8dp"
android:textSize="13dp"
android:text="To be Evaluated"
android:textColor="#color/white"
app:layout_constraintStart_toEndOf="#+id/tvTobeReceived"
app:layout_constraintTop_toBottomOf="#+id/ivBox2" />
</androidx.constraintlayout.widget.ConstraintLayout>
</RelativeLayout>
<TextView
android:id="#+id/TvRecommendation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Recommended"
android:layout_marginTop="25dp"
android:layout_centerHorizontal="true"
android:layout_below="#+id/Rl1"/>
<GridView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/GvRecommendations"
android:layout_below="#+id/TvRecommendation"
android:numColumns="2"
android:verticalSpacing="5dp"
/>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
I think your layout is too unnecessary complicated. The highest RelativeLayout does nothing here. Make ScrollView your root view and set it's width and height to match parent.
Try it:
<androidx.core.widget.NestedScrollView
android:layout_width="wrap_content"
android:layout_height="match_parent">
...
</androidx.core.widget.NestedScrollView>
Also You can try to set "android:layout_height="match_parent">" for ScrollView and set "android:layout_height="wrap_content">" for its child layout.

How to scroll layout when keyboard pops up in android

I have made the following layout using coordinator layout. But when the keyboard pops up some of the elements go below the keyboard hence losing the visibility.
So please help me to fix that.I have tried putting adjustPan, adjustResize in windowSoftInputMode but still not working. Even tried with the nested scroll view, no success.
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbarLayout"
android:layout_width="match_parent"
android:layout_height="300dp"
android:background="#drawable/gradient"
android:gravity="center">
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center|center_vertical"
android:background="#drawable/app_main_logo" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|center_vertical"
android:layout_marginTop="20dp"
android:text="My App"
android:textColor="#fff"
android:textSize="20dp" />
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.CardView
android:id="#+id/loginCardView"
android:layout_width="match_parent"
android:layout_height="250dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="250dp"
app:cardCornerRadius="10dp"
app:cardElevation="8dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:paddingLeft="30dp"
android:paddingRight="30dp">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:background="#fff">
<EditText
android:id="#+id/input_email_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="40dp"
android:hint="Username"
android:inputType="textEmailAddress"
android:textColor="#fff"
android:textColorHint="#fff" />
</android.support.design.widget.TextInputLayout>
<!-- Password Label -->
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:background="#fff"
app:passwordToggleEnabled="true">
<EditText
android:id="#+id/input_password_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword"
android:textColor="#fff"
android:textColorHint="#fff" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/capsule_button"
android:elevation="20dp"
android:gravity="center"
android:text="Sign In"
android:textColor="#fff"
android:textSize="20dp"
app:layout_anchor="#id/loginCardView"
app:layout_anchorGravity="bottom|center" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Don't have an account?" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:text="Create Now"
android:textStyle="bold" />
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
Use card view to top root then use any other layout with in it...!
Well you can use Scrollview,It will enable scrolling. So you can scroll all layout upside and downside.Do try this, if you don't want this you can also check Collapsing Toolbars. From here
https://material.io/develop/android/components/collapsing-toolbar-layout/
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff">
//This is Scrollview you can adjust height and width as you want.
<ScrollView android:layout_marginTop="30dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/scrollView">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbarLayout"
android:layout_width="match_parent"
android:layout_height="300dp"
android:background="#drawable/gradient"
android:gravity="center">
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center|center_vertical"
android:background="#drawable/app_main_logo" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|center_vertical"
android:layout_marginTop="20dp"
android:text="My App"
android:textColor="#fff"
android:textSize="20dp" />
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.CardView
android:id="#+id/loginCardView"
android:layout_width="match_parent"
android:layout_height="250dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="250dp"
app:cardCornerRadius="10dp"
app:cardElevation="8dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:paddingLeft="30dp"
android:paddingRight="30dp">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:background="#fff">
<EditText
android:id="#+id/input_email_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="40dp"
android:hint="Username"
android:inputType="textEmailAddress"
android:textColor="#fff"
android:textColorHint="#fff" />
</android.support.design.widget.TextInputLayout>
<!-- Password Label -->
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:background="#fff"
app:passwordToggleEnabled="true">
<EditText
android:id="#+id/input_password_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword"
android:textColor="#fff"
android:textColorHint="#fff" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/capsule_button"
android:elevation="20dp"
android:gravity="center"
android:text="Sign In"
android:textColor="#fff"
android:textSize="20dp"
app:layout_anchor="#id/loginCardView"
app:layout_anchorGravity="bottom|center" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Don't have an account?" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:text="Create Now"
android:textStyle="bold" />
</LinearLayout>
</ScrollView>
</android.support.design.widget.CoordinatorLayout>

how to center invisible Button

i'm trying to make (try again) button in center this button is invisible , i already tried to put : android:layout_gravity="center"
but doesn't work any suggestions for resolve this problems
This what he give me :
My XML file :
<?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:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#ffff"
android:id="#+id/activity_viewsol">
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar_top"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="#color/colorPrimary"
app:theme="#style/ThemeOverlay.AppCompat.Light"
android:fitsSystemWindows="true"
app:layout_collapseMode="pin"
android:elevation="5dp"
app:navigationIcon="#drawable/ic_back"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textColor="#ffffff"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="48sp"
android:textStyle="bold"
android:text="Solution"
android:id="#+id/toolbar_title" />
</android.support.v7.widget.Toolbar>
</RelativeLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:id="#+id/scrollview"
android:stackFromBottom="true"
android:scrollbarSize="10dp"
android:scrollbarThumbVertical="#drawable/scrollbar"
android:transcriptMode="alwaysScroll">
<LinearLayout
android:id="#+id/All_Layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="6dp"
android:padding="15dp">
<TextView
android:typeface="normal"
android:layout_gravity="center"
android:id="#+id/prob"
android:textStyle="bold"
android:textColor="#383838"
android:gravity="center"
android:textSize="45sp"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:layout_weight="1" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_marginBottom="20dp">
<View
android:layout_height="1dp"
android:layout_width="500dp"
android:background="#000"
android:layout_gravity="center"/>
<TextView
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="O"
android:textSize="40sp"
android:textColor="#color/colorAccent"
android:textStyle="bold"
android:layout_gravity="center"/>
<View
android:layout_height="1dp"
android:layout_width="500dp"
android:background="#000"
android:layout_gravity="center" />
</LinearLayout>
<TextView
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="35sp"
android:textStyle="normal"
android:textColor="#383838"
android:id="#+id/sol"
android:typeface="normal"
android:layout_marginBottom="20dp"/>
<View
android:id="#+id/LineHorizontalTwo"
android:layout_height="1dp"
android:layout_width="1000dp"
android:background="#000"
android:layout_gravity="center"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#null"
android:layout_margin="20dp"
android:layout_gravity="start|center"
android:id="#+id/Like"
android:src="#mipmap/ic_like"
/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#null"
android:layout_margin="20dp"
android:layout_gravity="end|center"
android:id="#+id/sharesol"
android:src="#mipmap/ic_action_share"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="#mipmap/retry"
android:drawablePadding="10dp"
android:layout_gravity="center"
android:gravity="center"
android:visibility="gone"
android:id="#+id/retry"
android:onClick="onClickRetry"
android:background="#null"
android:padding="6dp"
android:textSize="35sp"
android:text="TRY AGAIN"
android:textColor="#000" />
</LinearLayout>
You can do it simply doing by enclosing your error button inside the Relative Layout as following steps:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<Button
android:id="#+id/retry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#null"
android:drawablePadding="10dp"
android:drawableTop="#drawable/ic_android"
android:gravity="center"
android:padding="6dp"
android:text="TRY AGAIN"
android:textColor="#000"
android:textSize="35sp"
android:visibility="visible" />
</RelativeLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"/>
also you need a RelativeLayout for parent of this tag
Make the parent layout as RelativeLayout and put everything inside RelativeLayout except the button.
use
<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">
<!--Put your other codes here-->
<!--everything can be within LinerarLayout-->
<Button
android:id="#+id/retry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="#null"
android:drawablePadding="10dp"
android:drawableTop="#mipmap/retry"
android:onClick="onClickRetry"
android:padding="6dp"
android:text="TRY AGAIN"
android:textColor="#000"
android:textSize="35sp"
android:visibility="gone" />
</RelativeLayout>
as your button code

Categories