RecyclerView is taking full screen to show one message - android

i am working on a layout for chat screen in which i am using RecyclerView to show messages sent and receive by user but the problem which i am facing is RecyclerView is showing only one message in whole screen and to see other message i have to scroll down or scroll up. i want to show messages next to eachother vertically.
Here is my xml code:-
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/chatparent"
android:background="#color/background">
<include layout="#layout/chattoolbar"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_messages"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:scrollbars="vertical"
android:scrollbarStyle="outsideOverlay"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="bottom">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<FrameLayout
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="0.80"
android:background="#color/colorPrimary" />
<FrameLayout
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_weight="0.20"
android:background="#color/black"/>
</LinearLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/rl_typing"
android:background="#drawable/chatbox"
android:orientation="horizontal"
android:paddingLeft="5dp"
android:paddingRight="10dp"
android:layout_marginStart="15dp"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="2dp"
>
<Button
android:layout_width="20dp"
android:layout_height="20dp"
android:background="#drawable/ic_emoticons"
android:layout_marginTop="8dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:gravity="bottom"
android:id="#+id/btn_emoji"
/>
<EditText
android:layout_width="190dp"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:minLines="1"
android:maxLines="20"
android:lines="8"
android:imeActionId="#+id/send"
android:imeActionLabel="actionSend"
android:imeOptions="actionSend"
android:scrollbars="vertical"
android:textColor="#color/monsoon"
android:textColorHint="#color/dark_gray"
android:id="#+id/et_message"
android:textSize="13sp"
android:hint=" Type Your Message Here..."
android:layout_toEndOf="#id/btn_emoji"
tools:ignore="HardcodedText" />
<Button
android:layout_width="20dp"
android:layout_height="20dp"
android:background="#drawable/ic_attachment"
android:layout_marginTop="8dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:gravity="bottom"
android:id="#+id/btn_attach"
android:layout_toEndOf="#id/et_message"/>
<Button
android:layout_width="20dp"
android:layout_height="20dp"
android:background="#drawable/ic_camera"
android:layout_marginTop="8dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:id="#+id/btn_camera"
android:layout_toEndOf="#id/btn_attach"/>
</RelativeLayout>
<Button
android:layout_width="30dp"
android:layout_height="35dp"
android:id="#+id/btn_send"
android:layout_alignParentTop="true"
android:layout_marginTop="7.5dp"
android:layout_centerHorizontal="true"
android:layout_marginStart="3dp"
android:layout_toEndOf="#id/rl_typing"
android:background="#drawable/ic_send" />
</RelativeLayout>
</LinearLayout>
Here is the recyclerView_item.xml :-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:paddingLeft="10dp">
<TextView
android:id="#+id/username"
style="?android:textAppearanceMedium"
android:textColor="?android:textColorPrimary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textStyle="bold"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/txtOther"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16dp"
android:textColor="#color/black"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:background="#drawable/chat_in"/>
<TextView
android:id="#+id/message"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/chat_out"
android:paddingBottom="5dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="5dp"
android:textColor="#color/white"
android:textSize="16dp" />
<TextView
android:id="#+id/lblDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12dp"
android:textColor="#color/colorprimarylight"
android:textStyle="italic"
android:padding="5dp"
/>
</LinearLayout>
</LinearLayout>
Here is the screenshot in which you can see how much space it is producing in between two messages.

set recyclerview item's main layout height "wrap_content"

In child view of recyclerView set xml root to "wrap_content". If you set a flag match_parent it will take all space and you need to scroll your parent view.

In recyclerView_item.xml, you must set your 'main' LinearLayout's height and width match_parent to wrap_content

Related

How to align TextView + RecyclerView at screen bottom within ScrollView?

I have the next structure of XML file in my Fragment. I have an issue with RelativeLayout 3 (id=referralsContainer). It consist of textView (id=inviteText) + RecyclerView (id=rv_referrals). I need to show textView at the bottom of screen with any resolution. And after that textView must be RecyclerView with elements (when user will scroll down). I tried to do something like this in method, when all elements of recyclerview loaded, but recyclerview is replaced in different positions by Y axe from time to time, I can't understand how to correctly place that textview at the bottom of the scrren. And also ScrollView cuts several items of recyclerView. Does anybody can help with this? All positions in debugger looks right. Code+xml is below image. Thanks.
this.dataSourceListForAdapter.addAll(incomeListOfItemsFromServer);
recyclerView.setY(scrollView.getBottom() - textView.getHeight());
recyclerView.setY(coordinatorView.getBottom() - textView.getHeight());
adapter.notifyDataSetChanged();
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/invite_friends_swipe_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="#+id/invite_friends_content_part"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:visibility="visible">
<RelativeLayout
android:id="#+id/invite_friends_container"
android:layout_width="match_parent"
android:layout_height="190dp"
android:layout_alignParentTop="true"
android:background="#color/re_black_light_new">
<TextView
android:id="#+id/invite_friends_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/invite_friends_button_container"
android:gravity="center"
android:paddingEnd="40dp"
android:paddingStart="40dp"
android:textColor="#color/white"
android:textSize="16sp"
tools:text="#string/friends_invite_message" />
<RelativeLayout
android:id="#+id/invite_friends_button_container"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true">
<View
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_alignParentTop="true"
android:layout_marginTop="2dp"
android:background="#drawable/combined_shape_white" />
<View
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_alignParentBottom="true"
android:background="#color/white" />
<android.support.v7.widget.CardView
android:id="#+id/invite_friends_button_invite"
android:layout_width="147dp"
android:layout_height="40dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_gravity="center"
android:layout_marginTop="10dp"
card_view:cardBackgroundColor="#color/white"
card_view:cardCornerRadius="3dp"
card_view:cardElevation="2dp"
card_view:cardPreventCornerOverlap="false"
card_view:cardUseCompatPadding="true">
<TextView
android:id="#+id/invite_friends_button_invite_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/yellow_button_selector"
android:clickable="true"
android:focusable="true"
android:fontFamily="sans-serif-medium"
android:gravity="center"
android:text="#string/friends_invite"
android:textAllCaps="true"
android:textColor="#color/re_black_light_new"
android:textSize="14sp" />
</android.support.v7.widget.CardView>
</RelativeLayout>
</RelativeLayout>
<TextView
android:id="#+id/copy_choice_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/invite_friends_container"
android:layout_centerHorizontal="true"
android:textSize="12sp"
android:text="#string/copy_link_text"
android:textColor="#color/re_gray_new" />
<RelativeLayout
android:id="#+id/invite_friends_referal_link_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/copy_choice_label"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="16dp"
android:background="#drawable/rectangle_gray">
<TextView
android:id="#+id/invite_friends_referal_link_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:fontFamily="sans-serif-light"
android:gravity="center"
android:padding="7dp"
android:textColor="#color/re_black_light"
android:textSize="12sp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/invite_friends_full_info_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/invite_friends_referal_link_button"
android:layout_marginTop="32dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_marginStart="24dp"
android:layout_toLeftOf="#+id/invite_friends_container_central"
android:gravity="center_vertical">
<TextView
android:id="#+id/invite_friends_text_friends"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-medium"
android:text="#string/friends_invite_friends"
android:textColor="#color/re_black_light_new"
android:textSize="12sp" />
<TextView
android:id="#+id/invite_friends_friends_count"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/invite_friends_text_friends"
android:layout_marginTop="4dp"
android:fontFamily="sans-serif-medium"
android:textColor="#color/re_black_light_new"
android:textSize="24sp"
tools:text="4" />
<View
android:id="#+id/invite_friends_divider_horizontal"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="#+id/invite_friends_friends_count"
android:layout_marginTop="8dp"
android:background="#drawable/dash_horizontal_gray"
android:layerType="software" />
<TextView
android:id="#+id/invite_friends_text_orders"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_below="#+id/invite_friends_divider_horizontal"
android:layout_marginTop="14dp"
android:fontFamily="sans-serif-medium"
android:text="#string/friends_invite_orders"
android:textColor="#color/re_black_light_new"
android:textSize="12sp" />
<TextView
android:id="#+id/invite_friends_orders_count"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/invite_friends_text_orders"
android:layout_marginTop="4dp"
android:fontFamily="sans-serif-medium"
android:textColor="#color/re_black_light_new"
android:textSize="24sp"
tools:text="32" />
</RelativeLayout>
<View
android:id="#+id/invite_friends_container_central"
android:layout_width="1dp"
android:layout_height="1dp"
android:layout_centerInParent="true"
android:background="#drawable/dotted_line"
android:layerType="software" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginStart="10dp"
android:layout_toRightOf="#+id/invite_friends_container_central">
<TextView
android:id="#+id/invite_friends_income_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="6dp"
android:fontFamily="sans-serif-medium"
android:text="#string/friends_invite_income"
android:textColor="#color/re_black_light_new"
android:textSize="12sp" />
<LinearLayout
android:id="#+id/invite_friends_income_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/invite_friends_income_text"
android:layout_marginTop="4dp"
android:orientation="horizontal">
<TextView
android:id="#+id/invite_friends_income_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="6dp"
android:fontFamily="sans-serif-medium"
android:lines="1"
android:maxLines="1"
android:textColor="#color/re_black_light_new"
android:textSize="24sp"
tools:text="1488.77" />
<TextView
android:id="#+id/invite_friends_income_currency"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:fontFamily="sans-serif-medium"
android:lines="1"
android:maxLines="1"
android:textColor="#color/re_black_light_new"
android:textSize="12sp"
tools:text="руб." />
</LinearLayout>
<View
android:id="#+id/invite_friends_divider_horizontal_2"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="#+id/invite_friends_income_container"
android:layout_marginEnd="16dp"
android:layout_marginTop="8dp"
android:background="#drawable/dash_horizontal_gray"
android:layerType="software" />
<TextView
android:id="#+id/invite_friends_text_income_pending"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/invite_friends_divider_horizontal_2"
android:layout_marginStart="6dp"
android:layout_marginTop="14dp"
android:fontFamily="sans-serif-medium"
android:text="#string/friends_invite_income_pending"
android:textColor="#color/re_black_light"
android:textSize="12sp" />
<LinearLayout
android:id="#+id/invite_friends_text_income_pending_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/invite_friends_text_income_pending"
android:layout_marginStart="6dp"
android:layout_marginTop="4dp"
android:orientation="horizontal">
<TextView
android:id="#+id/invite_friends_text_income_pending_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-medium"
android:textColor="#color/re_gray_new"
android:textSize="24sp"
tools:text="0" />
<TextView
android:id="#+id/invite_friends_text_income_pending_count_currency"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:fontFamily="sans-serif-medium"
android:lines="1"
android:maxLines="1"
android:textColor="#color/re_gray_new"
android:textSize="12sp"
tools:text="руб."/>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/referralsContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/invite_friends_content_part"
android:visibility="gone"
android:orientation="vertical">
<TextView
android:id="#+id/inviteText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:fontFamily="sans-serif-medium"
android:text="Вы уже пригласили:"
android:textColor="#color/re_black_light_new"
android:textSize="20sp"
android:textStyle="normal" />
<ImageView
android:id="#+id/scrollMore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/inviteText"
android:layout_centerHorizontal="true"
android:layout_marginBottom="6dp"
android:layout_marginTop="6dp"
android:src="#drawable/ic_scroll_more" />
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_referrals"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/scrollMore"
android:scrollbars="vertical" />
</RelativeLayout>
</RelativeLayout>
<LinearLayout
android:id="#+id/invite_friends_error_part"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone">
<ImageView
android:id="#+id/error_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:layout_marginTop="20dp"
android:scaleType="fitCenter"
android:src="#drawable/lost_connection_holder" />
<TextView
android:id="#+id/error_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/error_image"
android:layout_marginBottom="60dp"
android:layout_marginTop="10dp"
android:gravity="center_horizontal"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:text="#string/no_connection_message"
android:textColor="#color/black_tr_38"
android:textSize="19sp" />
</LinearLayout>
</RelativeLayout>
</ScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
ScrollView is not purposed for sub-child layouts aligned to the bottom of screen as its direct child doesn't know where the bottom is. From your question is not clear how do you need (want) to scroll bottom part.
If it is ok to scroll by dragging bottom part (RelativeLayout 3) it is better to use BottomSheetBehaviour in Coordinatorlayout for this layout.
If not then just put RelativeLayout 3 under (below) SwipeRefreshLayout and handle ScrollView scrollChanged events to animate scrolling of bottom layout if you need or just show/hide this bottom layout.
Don't forget that on small resolutions layout aligned to the bottom will cover the content of ScrollView and user won't be able to scroll top layout.

android:gravity in TextView not working

When i apply android:gravity to center(or even textAlignment true for TextView) , the instant changes are applied to current activity (using my device for testing) and the text is centered .
But then when i install/restart app with the same changes (or come back to present activity from previous one), the text is left aligned at the start of the TextView .
TextView trying to center : android:id="#+id/ttamt
The text is centered only when i make changes while running app on the activity.
Really can't understand what wrong i am doing here ,
Thanks for your time and help .
Following is my layout code :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/mainRel"
android:layout_width="match_parent"
android:layout_height="300dp"
android:background="#5f5f5f"
android:elevation="10dp"
android:transitionName="#string/transtrans">
<ImageView
android:id="#+id/ttimg"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:src="#drawable/com_facebook_tooltip_blue_topnub"
android:transitionName="timgTrans" />
<TextView
android:id="#+id/ttamt"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_below="#+id/ttimg"
android:layout_marginTop="20dp"
android:fontFamily="sans-serif"
android:gravity="center"
android:text="1001"
android:textColor="#fff"
android:textSize="55sp"
android:textStyle="bold|italic"
android:transitionName="tamtTrans" />
<TextView
android:id="#+id/ttdate"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="#+id/ttamt"
android:layout_marginTop="25dp"
android:layout_toRightOf="#+id/timg"
android:fontFamily="sans-serif"
android:text="01/01/01"
android:textAlignment="center"
android:textColor="#fff"
android:textSize="22dp"
android:textStyle="bold|italic" />
</RelativeLayout>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#f0f0f0"
android:clickable="true"
android:elevation="15dp"
android:foreground="?android:attr/selectableItemBackground"
app:cardCornerRadius="7dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="#+id/ttdesc"
android:layout_width="150dp"
android:layout_height="45dp"
android:layout_gravity="center_vertical"
android:layout_marginLeft="20dp"
android:layout_marginTop="12dp"
android:fontFamily="sans-serif"
android:text="TestDesc"
android:textSize="16sp"
android:textStyle="bold|italic"
android:transitionName="tdescTrans" />
<ImageView
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_gravity="center_vertical"
android:layout_marginLeft="120dp"
android:src="#drawable/ic_mode_edit_black_24dp" />
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#f0f0f0"
android:clickable="true"
android:elevation="15dp"
android:foreground="?android:attr/selectableItemBackground"
app:cardCornerRadius="7dp">
<TextView
android:id="#+id/ttmsg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="10dp"
android:layout_marginTop="20dp"
android:lineSpacingExtra="5dp"
android:text="View SMS"
android:textSize="15dp" />
</android.support.v7.widget.CardView>
</LinearLayout>
Looks like an issue with api 18 or higher after seeing this answer.
Did the same , wrapped my views inside LinearLayout and used textAlignment="center" . Works fine now .
Final Layout Snippet :
<RelativeLayout
android:id="#+id/mainRel"
android:layout_width="match_parent"
android:layout_height="300dp"
android:background="#5f5f5f"
android:elevation="10dp"
android:transitionName="#string/transtrans">
<ImageView
android:id="#+id/ttimg"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:src="#drawable/com_facebook_tooltip_blue_topnub"
android:transitionName="timgTrans" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="80dp"
android:orientation="vertical">
<TextView
android:id="#+id/ttamt"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_below="#+id/ttimg"
android:fontFamily="sans-serif"
android:text="1001"
android:textAlignment="center"
android:textColor="#fff"
android:textSize="55sp"
android:textStyle="bold|italic"
android:transitionName="tamtTrans" />
<TextView
android:id="#+id/ttdate"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="#+id/ttamt"
android:layout_marginTop="25dp"
android:fontFamily="sans-serif"
android:text="01/01/01"
android:textAlignment="center"
android:textColor="#fff"
android:textSize="22dp"
android:textStyle="bold|italic" />
</LinearLayout>
</RelativeLayout>

Partial UI screen up

In a screen, I have a edit text on top (large contains space for 4-5 line), image view below that and submit button at bottom. on Keyboard up it should not hide my submit button.
when keyboard appears i am able to resize the window using android:windowSoftInputMode="adjustResize" which allow me not to hide the submit button but it resize my image also which i don't want.
Only submit button should move up when keyboard is visible without resizing image.
I tried frame layout also but it didn't may be i tried wrong way. Any help will be appriciated.
Apply this and let me know is it still happening or not .
activity_mian.xml
<ScrollView 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"
android:layout_gravity="center_vertical|center_horizontal"
android:background="#drawable/xxx.jpg"
android:orientation="vertical"
tools:context=".LoginActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="190dp"
android:layout_marginTop="20dp"
android:src="#drawable/logo_app" />
<EditText
android:id="#+id/edtEmail"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:background="#drawable/login_textbox"
android:ems="10"
android:hint="Email"
android:imeOptions="actionNext"
android:inputType="textEmailAddress"
android:singleLine="true"
android:textColor="#ffffff"
android:textCursorDrawable="#null" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/edtPassword"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_gravity="center_vertical|center_horizontal"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#drawable/login_textbox"
android:ems="10"
android:hint="Password"
android:imeOptions="actionDone"
android:inputType="textPassword"
android:singleLine="true"
android:textColor="#ffffff"
android:textCursorDrawable="#null" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentTop="true"
android:layout_alignRight="#+id/edtPassword"
android:layout_marginTop="2dp" />
</RelativeLayout>
<CheckBox
android:id="#+id/checkBox_remember"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:button="#drawable/checkbox_selector"
android:checked="true"
android:focusable="false"
android:focusableInTouchMode="true"
android:text=" Remember Me"
android:textColor="#ffffff" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="10dp"
android:orientation="vertical" >
<Button
android:id="#+id/btnLogin"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_gravity="top|center_vertical|center_horizontal"
android:layout_marginTop="10dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="#drawable/btn_login" />
</LinearLayout>
</LinearLayout>
</ScrollView>
set your Button, EditText etc.. inside one linear layout followed by one parent ScrollView .
one another thing is that set android:windowSoftInputMode="stateAlwaysHidden"
inside your java file where your xml file is bind .
With some changes in #jigs answer i got it working and posting may be it can help others like me
1) Root layout as normal in my case Relative layout. Then scroll view inside scroll view take a Linear layout where specify edit text + image View. Then bottom button.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/root_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?android:attr/actionBarSize"
android:background="#android:color/white"
android:orientation="vertical">
<ScrollView
android:id="#+id/scrollViewNotScrollable"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/user_name_container">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="vertical"
>
<EditText
android:id="#+id/input_feed"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#00000000"
android:ellipsize="start"
android:focusable="true"
android:focusableInTouchMode="true"
android:gravity="start|center_vertical"
android:hint="#string/feed_hint"
android:imeActionLabel="Submit"
android:imeOptions="actionSend"
android:inputType="textMultiLine|textAutoCorrect|textCapSentences"
android:maxLines="5"
android:minLines="3"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="25dp"
android:textColor="#color/feed_sub_color"
android:textColorHint="#color/light_gray"
android:textCursorDrawable="#null" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp">
<!--<ScrollView
android:id="#+id/scroll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:isScrollContainer="false"
android:padding="4dp"
android:layout_centerHorizontal="true"
>-->
<ImageView
android:id="#+id/imgPreview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_gravity="center"
android:layout_marginBottom="20dp"
android:layout_marginTop="20dp"
android:adjustViewBounds="true"
android:background="#android:color/white"
android:elevation="5dp"
android:padding="4dp"
android:visibility="gone" />
<!--</ScrollView>-->
<ImageView
android:id="#+id/close_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/imgPreview"
android:layout_marginLeft="-45dp"
android:layout_marginTop="-20dp"
android:layout_toRightOf="#+id/imgPreview"
android:elevation="5dp"
android:paddingBottom="15dp"
android:src="#drawable/closeimage"
android:visibility="gone" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
<RelativeLayout
android:id="#+id/user_name_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:fitsSystemWindows="true">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#android:color/darker_gray" />
<EditText
android:id="#+id/feed_user_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:background="#null"
android:ellipsize="end"
android:fontFamily="san-serif-condensed"
android:padding="12dp"
android:singleLine="true"
android:text="sherry's phone"
android:textColor="#android:color/black"
android:textSize="#dimen/feed_name_size"
android:visibility="gone" />
<TextView
android:id="#+id/feed_user_name_textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:background="#null"
android:ellipsize="end"
android:fontFamily="san-serif-condensed"
android:padding="12dp"
android:paddingLeft="20dp"
android:singleLine="true"
android:text="sherry's phone"
android:textColor="#android:color/black"
android:textSize="#dimen/feed_name_size" />
<ImageView
android:id="#+id/edit_name"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_alignParentRight="true"
android:layout_gravity="end"
android:layout_marginBottom="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:scaleType="centerInside"
android:src="#drawable/editname" />
<Button
android:id="#+id/done"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_alignParentRight="true"
android:layout_marginBottom="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:background="#drawable/rounded_corner_update_block"
android:fontFamily="san-serif-medium"
android:text="Done"
android:textColor="#android:color/white"
android:visibility="gone" />
</RelativeLayout>
</RelativeLayout>
2)android:windowSoftInputMode="adjustResize" in your manifest.xml
3) disable scroll in java code (optional)
mScrollView.setOnTouchListener( new OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event)
{
return true;
}
});

How to dynamically change the coordinates of views under the listview

I have such xml:
on screen
I want to change the coordinates of layout "#+id/ifPopulate" every time when user will populate or remove items from listview (in other words, I want to have same distance between listview and layout #+id/ifPopulate").
And layout #+id/ifPopulate" don't have to be lower, than layout "#+id/buttons_at_the_bottom".
Here is my code. ListView's height need to be wrap_content, of course. I wrote "100 dp" just for example:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#color/blue_normal"
android:padding="10dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:id="#+id/ifSpinnerAddTextEdit"
android:orientation="vertical"
>
<ListView
android:id="#+id/lv2"
android:layout_width="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:background="#color/white"
android:layout_marginBottom="5dp"
android:layout_height="100dp">
</ListView>
<LinearLayout
android:id="#+id/ifPopulate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="#+id/addItemNumTv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="17sp"
android:layout_gravity="top"
android:text="#string/item_one" />
<EditText
android:id="#+id/addItemValEt1"
android:layout_width="0dp"
android:textColor="#color/grey"
android:paddingLeft="8dp"
android:layout_marginLeft="10dp"
android:textSize="17sp"
android:layout_weight="1"
android:layout_gravity="top"
android:layout_height="40dp"
android:textCursorDrawable="#null"
android:inputType="textCapSentences" />
<Button
android:id="#+id/addItemValBut1"
android:layout_width="#dimen/lview_top_margin"
android:textColor="#color/white"
android:textSize="12sp"
android:layout_height="#dimen/lview_top_margin"
android:layout_gravity="top"
android:layout_marginLeft="10dp"
android:text="#string/ok" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_marginTop="10dp"
android:paddingBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_height="wrap_content"
android:id="#+id/buttons_at_the_bottom">
<Button
android:id="#+id/saveCreateTemplateDialog"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:layout_marginRight="5dp"
android:onClick="getArrayProd"
android:textColor="#color/white"
android:text="#string/save"/>
<Button
android:id="#+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:layout_gravity="bottom"
android:layout_marginLeft="5dp"
android:onClick="getArrayProd"
android:textColor="#color/white"
android:text="#string/back"/>
</LinearLayout>
</LinearLayout>

Slim Spinner when i use FILL_PARENT (or MATCH_PARENT) as WIDTH

i've a strange problem when i set android:layout_width="fill_parent" in my Spinner:
the clickable area is reduced to a line (red square) and only pressing on this line is possibile show the elements of the Spinner:
if i use android:layout_width="wrap_content" i obtain the correct area:
i would like the same thing using "fill_parent"
The elements of the Spinner are correctly visualized.. The only problem is clicking on the Spinner.
Which is the possible problem?
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#040404"
android:gravity="center"
android:paddingTop="2dp"
android:weightSum="4" >
<TextView
android:id="#+id/mpp_movimento_lbl"
android:background="#drawable/selector_black_btn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableTop="#drawable/freccia_verde"
android:gravity="center"
android:text="#string/Movimento"
android:textColor="#color/white"
android:textStyle="bold"
android:textSize="17sp" />
<TextView
android:id="#+id/mpp_eccesso_lbl"
android:background="#drawable/selector_black_btn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableTop="#drawable/freccia_rossa"
android:gravity="center"
android:text="#string/Eccesso"
android:textColor="#color/white"
android:textStyle="bold"
android:textSize="17sp" />
<TextView
android:id="#+id/mpp_fermo_lbl"
android:background="#drawable/selector_black_btn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableTop="#drawable/freccia_grigia"
android:gravity="center"
android:text="#string/Fermo"
android:textColor="#color/white"
android:textStyle="bold"
android:textSize="17sp" />
<TextView
android:id="#+id/mpp_ripristina_lbl"
android:background="#drawable/selector_black_btn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableTop="#drawable/ripristina_mappa_40x40"
android:gravity="center"
android:text="#string/Ripristina"
android:textColor="#color/white"
android:textStyle="bold"
android:textSize="17sp" />
</LinearLayout>
<TextView
android:id="#+id/mpp_automezzi_visualizzati_lbl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/black"
android:gravity="center"
android:paddingTop="5dp"
android:text="#string/AutomezziVisualizzati"
android:textColor="#color/white"
android:textSize="17sp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:paddingTop="5dp" >
<FrameLayout
android:id="#+id/mpp_spinner_frame_fly"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/mpp_cerca_btn" >
<Spinner
android:id="#+id/mpp_spinner_spn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:textSize="17sp" />
</FrameLayout>
<ImageButton
android:id="#+id/mpp_cerca_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:background="#drawable/selector_white_btn"
android:contentDescription="#string/DescrizioneCerca"
android:gravity="center"
android:onClick="doCerca"
android:src="#drawable/cerca" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="5dp"
android:background="#040404"
android:gravity="center" >
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<fragment
android:id="#+id/mpp_mappa_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
class="com.google.android.gms.maps.SupportMapFragment" />
</RelativeLayout>
Try setting your Spinner's parent's height to match_parent. And also do you really need such layout? There is no need to place spinner in FrameLayout, try setting spinners's weight to 1 and replace RelativeLayout with LinearLayout

Categories

Resources