I'm trying to reduce the number of hierarchies on my list item so I have only one RelativeLayout, but I'm struggling to understand how can I do the same behave of a LinearLayout.
For example:
<RelativeLayout
android:id="#+id/ordercardcontentrow"
android:layout_width="match_parent"
local:MvxBind="BackgroundColor NativeColor(BackgroundColour)"
android:layout_marginBottom="4dp"
android:layout_marginLeft="1dp"
android:layout_marginRight="1dp"
android:layout_height="match_parent">
<TextView
android:layout_marginTop="10dp"
android:layout_toRightOf="#id/order_classification_image"
android:id="#+id/order_header"
style="#style/NormalText.Regular"
android:layout_width="160dp"
android:textSize="#dimen/text_size_small"
android:ellipsize="end"
android:singleLine="true"
local:MvxBind="Text OrderHeader" />
<TextView
android:layout_marginTop="2dp"
android:layout_toRightOf="#id/order_classification_image"
android:id="#+id/post_code"
android:layout_below="#id/order_header"
style="#style/TitleText.Regular"
android:textSize="#dimen/text_size_vlarge"
android:ellipsize="end"
android:singleLine="true"
local:MvxBind="Text Postcode; Visible IsDelivery" />
<TextView
android:layout_marginTop="2dp"
android:layout_toRightOf="#id/order_classification_image"
android:id="#+id/order_id"
style="#style/NormalText.Medium"
android:layout_below="#id/post_code"
android:textSize="#dimen/text_size_vsmall"
android:textColor="#color/dark_grey"
local:MvxBind="Text FormattedOrderId" />
</RelativeLayout>
But if the middle one is not visible of course the are not going to be vertically centred in my relative layout, how can I make this happen?
Cheers!
Try that (adapt it to your needs):
remember, android:layout_width and height are mandatory.
<RelativeLayout
android:id="#+id/ordercardcontentrow"
android:layout_width="match_parent"
android:gravity="center_vertical"
android:layout_height="match_parent"
android:layout_marginBottom="4dp"
android:layout_marginLeft="1dp"
android:layout_marginRight="1dp">
<TextView
android:id="#+id/order_header"
android:layout_width="160dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:ellipsize="end"
android:text="AAAA" />
<TextView
android:visibility="gone"
android:id="#+id/post_code"
android:layout_width="160dp"
android:layout_height="wrap_content"
android:layout_below="#id/order_header"
android:layout_marginTop="2dp"
android:ellipsize="end"
android:text="BBBB" />
<TextView
android:id="#+id/order_id"
android:layout_width="160dp"
android:layout_height="wrap_content"
android:layout_below="#id/post_code"
android:layout_marginTop="2dp"
android:text="CCCC"
/>
</RelativeLayout>
Use gravity center android:gravity="center" for relativelayout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ordercardcontentrow"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="4dp"
android:layout_marginLeft="1dp"
android:layout_marginRight="1dp"
android:gravity="center">
<TextView
android:id="#+id/order_header"
android:layout_width="160dp"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:ellipsize="end"
android:text="sdff" />
<TextView
android:id="#+id/post_code"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/order_header"
android:layout_marginTop="2dp"
android:ellipsize="end"
android:text="sdff" />
<TextView
android:id="#+id/order_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/post_code"
android:layout_marginTop="2dp"
android:text="sdff" />
</RelativeLayout>
Related
I have the farrowing code that I am using to dynamically place items in gridview
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="350dp"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_margin="#dimen/margin_small"
card_view:cardCornerRadius="10dp"
card_view:cardElevation="#dimen/margin_small">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin_small"
android:layout_gravity="center">
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/name"
card_view:layout_constraintTop_toTopOf="parent"
card_view:layout_constraintBottom_toTopOf="#+id/cost"
card_view:layout_constraintStart_toStartOf="#+id/image"
android:maxLines="3"
android:padding="9dp"
android:textAppearance="?android:attr/textAppearanceSmall"/>
<TextView
android:id="#+id/cost"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/ksh_000_00"
card_view:layout_constraintTop_toBottomOf="#+id/name"
card_view:layout_constraintBottom_toTopOf="#+id/image"
card_view:layout_constraintStart_toStartOf="#+id/image"
android:textAppearance="?android:attr/textAppearanceSmall"
android:typeface="serif"/>
<ImageView
android:id="#+id/image"
android:layout_width="match_parent"
android:layout_height="150dp"
android:contentDescription="#string/food_fuzz_logo"
android:src="#drawable/logo"
card_view:layout_constraintBottom_toTopOf="#+id/footer"
card_view:layout_constraintEnd_toEndOf="parent"
card_view:layout_constraintStart_toStartOf="parent"
card_view:layout_constraintTop_toBottomOf="#+id/cost"
tools:scaleType="fitCenter" />
<LinearLayout
android:layout_width="match_parent"
android:id="#+id/footer"
android:layout_height="wrap_content"
card_view:layout_constraintTop_toBottomOf="#+id/image"
card_view:layout_constraintBottom_toBottomOf="parent"
card_view:layout_constraintEnd_toEndOf="#+id/image"
card_view:layout_constraintStart_toStartOf="#+id/name"
android:orientation="horizontal"
android:background="#color/gradient_background">
<TextView
android:id="#+id/minus"
android:layout_width="14dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:layout_marginStart="#dimen/activity_vertical_margin"
android:gravity="start"
android:text="#string/minus"
android:textColor="#color/white"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:layout_width="30dp"
android:layout_height="wrap_content"
android:id="#+id/quantity"
android:text="#string/zero"
android:textColor="#color/white"
android:textSize="18sp"
android:textStyle="bold"
android:layout_gravity="center"
android:gravity="center"/>
<TextView
android:layout_width="30dp"
android:layout_height="wrap_content"
android:id="#+id/plus"
android:text="#string/plus"
android:textColor="#color/white"
android:textSize="18sp"
android:textStyle="bold"
android:layout_gravity="end"
android:gravity="end"/>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
now I would like to have it like the bootstrap card with card-header, card-body and card-footer effect but I am only able to make it have the body like effect only. My attempt for the footer only positions the footer id element in the centre and its components crumbled together instead of the first one(minus) being spread out one to the extreme left, the other(quantity) in the centre and the last one(plus)n to the extreme right of the cardview's linear layout item.
This is what the code gives me
And this is what I expect
yet what I want is for the grey area to span the entire width of the card view and position the components appropriately as explained earlier
How is it possible to achieve my design idea?
what I want is for the grey area to span the entire width of the card view
I see that you used tools:scaleType for the image, and this won't work at runtime, as tools namespace is used for design purpose, so change it to android:scaleType
and position the components appropriately as explained earlier
You need to set the width of the LinearLayout that holds the buttons to match_parent, and set the weight values so that the buttons can be distribute like you need:
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="350dp"
android:layout_margin="#dimen/margin_small"
card_view:cardCornerRadius="10dp"
card_view:cardElevation="#dimen/margin_small">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="#dimen/margin_small">
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="3"
android:padding="9dp"
android:text="#string/name"
android:textAppearance="?android:attr/textAppearanceSmall"
card_view:layout_constraintBottom_toTopOf="#+id/cost"
card_view:layout_constraintStart_toStartOf="#+id/image"
card_view:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/cost"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/ksh_000_00"
android:textAppearance="?android:attr/textAppearanceSmall"
android:typeface="serif"
card_view:layout_constraintBottom_toTopOf="#+id/image"
card_view:layout_constraintStart_toStartOf="#+id/image"
card_view:layout_constraintTop_toBottomOf="#+id/name" />
<ImageView
android:id="#+id/image"
android:layout_width="match_parent"
android:layout_height="150dp"
android:scaleType="fitCenter"
android:src="#drawable/ic_launcher_background"
card_view:layout_constraintBottom_toTopOf="#+id/footer"
card_view:layout_constraintEnd_toEndOf="parent"
card_view:layout_constraintStart_toStartOf="parent"
card_view:layout_constraintTop_toBottomOf="#+id/cost"
tools:scaleType="fitCenter" />
<LinearLayout
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/gradient_background"
android:orientation="horizontal"
card_view:layout_constraintBottom_toBottomOf="parent"
card_view:layout_constraintEnd_toEndOf="#+id/image"
card_view:layout_constraintStart_toStartOf="#+id/name"
card_view:layout_constraintTop_toBottomOf="#+id/image">
<TextView
android:id="#+id/minus"
android:layout_width="14dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:layout_marginStart="#dimen/activity_vertical_margin"
android:gravity="start"
android:text="#string/minus"
android:layout_weight="1"
android:textColor="#color/white"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="#+id/quantity"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="#string/zero"
android:textColor="#color/white"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="#+id/plus"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:layout_marginEnd="#dimen/activity_vertical_margin"
android:layout_weight="1"
android:layout_gravity="end"
android:gravity="end"
android:text="#string/plus"
android:textColor="#color/white"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
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.
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
I have tried everything but not succeed yet.
What Happening. When title text is small it should come in center of parent which works perfectly, but when text size is big its overlapped to its left sided component
What i want : it shouldn't not overlap but comes to next of settings Textview. it should be adjust when size increased.
small size
big size
Code
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="#android:color/darker_gray" >
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Settings"
android:gravity="center_vertical"
android:layout_alignParentLeft="true"
android:textColor="#android:color/holo_orange_dark"
android:textSize="16.0sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="hiiiiiiiiiiiii StackOverflower!!!!!!!!!!!"
android:padding="4dp"
android:gravity="center"
android:layout_toLeftOf="#+id/txtBack"
android:textColor="#android:color/white"
android:textSize="19sp" />
</RelativeLayout>
Because you are using match_parent for those two TextViews, that is why they will being overlapped, based on your code, you can try to add a fix padding for the second TextView. For example, we consider the width of the first TextView's text "Settings" is 100dp, so we can change the code as below.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="#android:color/darker_gray" >
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Settings"
android:gravity="center_vertical"
android:layout_alignParentLeft="true"
android:textColor="#android:color/holo_orange_dark"
android:textSize="16.0sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="hiiiiiiiiiiiii StackOverflower!!!!!!!!!!!"
android:paddingTop="4dp"
android:paddingBottom="4dp"
android:paddingLeft="100dp"
android:paddingRight="100dp"
android:gravity="center"
android:layout_toLeftOf="#+id/txtBack"
android:textColor="#android:color/white"
android:textSize="19sp" />
</RelativeLayout>
set id to your first TextView and then make second TextView toRightOf first one.
Like This
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="#android:color/darker_gray" >
<TextView
android:id="#+id/textview1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Settings"
android:gravity="center_vertical"
android:layout_alignParentLeft="true"
android:textColor="#android:color/holo_orange_dark"
android:textSize="16.0sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toRightOf="#id/textview1"
android:text="hiiiiiiiiiiiii StackOverflower!!!!!!!!!!!"
android:padding="4dp"
android:gravity="center"
android:layout_toLeftOf="#+id/txtBack"
android:textColor="#android:color/white"
android:textSize="19sp" />
</RelativeLayout>
I hope this will help.
Try this,
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="#android:color/darker_gray" >
<TextView
android:id="#+id/txtSetting"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Settings"
android:gravity="center_vertical"
android:layout_alignParentLeft="true"
android:textColor="#android:color/holo_orange_dark"
android:textSize="16.0sp" />
<TextView
android:layout_toRightOf="#+id/txtSetting"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="hiiiiiiiiiiiii StackOverflower!!!!!!!!!!!"
android:padding="4dp"
android:gravity="center"
android:layout_toLeftOf="#+id/txtBack"
android:textColor="#android:color/white"
android:textSize="19sp" />
</RelativeLayout>
Use layout_toLeftOf ,alignParentLeft and alignParentRight
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Settings"
android:id="#+id/txtBack"
android:gravity="center_vertical"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/selectaccount"
android:textColor="#android:color/holo_orange_dark"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hiiiiiiiiiiiii StackOverflower!!!!!!!!!!!"
android:padding="4dp"
android:gravity="center"
android:layout_alignParentRight="true"
android:textColor="#android:color/white"
android:textAppearance="?android:attr/textAppearanceMedium" />
Just Replace Your Code By Below:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="56dp"
android:background="#android:color/darker_gray" >
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Settings"
android:gravity="center_vertical"
android:layout_alignParentLeft="true"
android:textColor="#android:color/holo_orange_dark"
android:textSize="16.0sp"
android:id="#+id/txtSettings" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="hiiiiiiiiiiiii StackOverflower!!!!!!!!!!!"
android:padding="4dp"
android:gravity="center"
android:layout_toRightOf="#+id/txtSettings"
android:layout_toLeftOf="#+id/txtBack"
android:textColor="#android:color/white"
android:textSize="19sp" />
</RelativeLayout>
change second textview to this:
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="hiiiiiiiiiiiii StackOverflower!!!!!!!!!!!"
android:padding="4dp"
android:gravity="center"
android:layout_toRightOf="#+id/firstTextview"
android:textColor="#android:color/white"
android:textSize="19sp" />
I'm trying to align text inside textview to the center (both vertical and horizontal).
Altought the vertical alignment working properlly in the Android Studio preview, it fails on the emulator.
The design:
The android studio preview:
The emulator:
The code:
<RelativeLayout
android:id="#+id/teamsBox"
android:layout_width="match_parent"
android:layout_height="185dp">
<LinearLayout
android:layout_width="154dp"
android:layout_height="wrap_content"
android:background="#drawable/team_bg"
android:padding="6dp"
android:layout_alignParentLeft="true"
android:orientation="vertical">
<EditText
android:id="#+id/teamOneName"
android:layout_width="143dp"
android:layout_height="42dp"
android:text="HOME"
android:textColor="#color/my_white"
android:background="#color/my_transparent"
android:textSize="23sp"
android:singleLine="true"
android:gravity="center"/>
<TextView
android:id="#+id/teamOneScore"
android:layout_width="143dp"
android:layout_height="132dp"
android:text="3"
android:textColor="#color/my_green"
android:textSize="127sp"
android:gravity="center"/>
</LinearLayout>
<LinearLayout
android:layout_width="154dp"
android:layout_height="match_parent"
android:background="#drawable/team_bg"
android:padding="6dp"
android:layout_alignParentRight="true"
android:orientation="vertical">
<EditText
android:id="#+id/teamTwoName"
android:layout_width="match_parent"
android:layout_height="42dp"
android:text="AWAY"
android:textColor="#color/my_white"
android:background="#color/my_transparent"
android:textSize="23sp"
android:singleLine="true"
android:gravity="center"/>
<TextView
android:id="#+id/teamTwoScore"
android:layout_width="fill_parent"
android:layout_height="132dp"
android:text="1"
android:textColor="#color/my_green"
android:textSize="127sp"
android:gravity="center"
android:layout_gravity="center"/>
</LinearLayout>
</RelativeLayout>
Edit: I've changed to layout according to the answers, but the bug is still happening.
This is my new layout:
<RelativeLayout
android:id="#+id/teamsBox"
android:layout_width="match_parent"
android:layout_height="185dp">
<LinearLayout
android:layout_width="154dp"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:background="#drawable/team_bg"
android:orientation="vertical"
android:padding="6dp" >
<EditText
android:id="#+id/teamOneName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="HOME"
android:textColor="#color/my_white"
android:background="#color/my_transparent"
android:textSize="23sp"
android:singleLine="true"
android:padding="8dp"
android:gravity="center"/>
<TextView
android:id="#+id/teamOneScore"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="3"
android:textColor="#color/my_green"
android:textSize="127sp"
android:gravity="center_vertical|center_horizontal"/>
</LinearLayout>
<LinearLayout
android:layout_width="154dp"
android:layout_height="match_parent"
android:background="#drawable/team_bg"
android:padding="6dp"
android:layout_alignParentRight="true"
android:orientation="vertical">
<EditText
android:id="#+id/teamTwoName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="AWAY"
android:textColor="#color/my_white"
android:background="#color/my_transparent"
android:textSize="23sp"
android:singleLine="true"
android:padding="8dp"
android:gravity="center"/>
<TextView
android:id="#+id/teamTwoScore"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="1"
android:textColor="#color/my_green"
android:textSize="127sp"
android:gravity="center"
android:layout_gravity="center"/>
</LinearLayout>
</RelativeLayout>
To problem is in the TextView itself, the large size of the text is not calculated by the gravity attribute.
Try adding this attribute to your text view android:includeFontPadding="false"
set your textView's android:gravity to center_vertical | center_horizontal
<TextView
android:id="#+id/teamOneScore"
android:layout_width="143dp"
android:layout_height="132dp"
android:text="3"
android:textColor="#color/my_green"
android:textSize="127sp"
android:gravity="center_vertical | center_horizontal" />
Remove hard coded width and height and use weight.Try the following data
<RelativeLayout
android:id="#+id/teamsBox"
android:layout_width="match_parent"
android:layout_height="185dp" >
<LinearLayout
android:layout_width="154dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:background="#drawable/button_background"
android:orientation="vertical"
android:padding="6dp" >
<EditText
android:id="#+id/teamOneName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#123456"
android:gravity="center"
android:singleLine="true"
android:text="HOME"
android:textSize="23sp" />
<TextView
android:id="#+id/teamOneScore"
android:layout_width="match_parent"
android:layout_height="0dp"
android:gravity="center_vertical|center_horizontal"
android:text="3"
android:layout_weight="1"
android:textSize="127sp" />
</LinearLayout>
<LinearLayout
android:layout_width="154dp"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:background="#drawable/button_background"
android:orientation="vertical"
android:padding="6dp" >
<EditText
android:id="#+id/teamTwoName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#123456"
android:gravity="center"
android:singleLine="true"
android:text="AWAY"
android:textSize="23sp" />
<TextView
android:id="#+id/teamTwoScore"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center"
android:gravity="center_vertical|center_horizontal"
android:text="1"
android:layout_weight="1"
android:textSize="127sp" />
</LinearLayout>
</RelativeLayout>
Hope this works
try this it may help you,
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/holo_green_light" >
<LinearLayout
android:layout_width="154dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:orientation="vertical"
android:padding="6dp" >
<EditText
android:id="#+id/teamOneName"
android:layout_width="143dp"
android:layout_height="42dp"
android:background="#android:color/holo_green_dark"
android:gravity="center"
android:singleLine="true"
android:text="HOME"
android:textColor="#android:color/white"
android:textSize="23sp" />
<TextView
android:id="#+id/teamOneScore"
android:layout_width="143dp"
android:layout_height="132dp"
android:gravity="center"
android:text="3"
android:background="#android:color/white"
android:textSize="127sp" />
</LinearLayout>
<LinearLayout
android:layout_width="154dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:orientation="vertical"
android:padding="6dp" >
<EditText
android:id="#+id/teamTwoName"
android:layout_width="match_parent"
android:layout_height="42dp"
android:background="#android:color/holo_green_dark"
android:gravity="center"
android:singleLine="true"
android:text="AWAY"
android:textColor="#android:color/white"
android:textSize="23sp" />
<TextView
android:id="#+id/teamTwoScore"
android:layout_width="fill_parent"
android:layout_height="132dp"
android:layout_gravity="center"
android:gravity="center"
android:text="1"
android:background="#android:color/white"
android:textSize="127sp" />
</LinearLayout>
</RelativeLayout>
Just use match_parent as the height of the textview.
Your linear layout which is having the edit text and one text view height is lesser than you have given height to its children. Please calculate height for the edit text and text view and accordingly adjust height of your linear layout.
Here You just need to give wrap_content to you text view and .
1. change in text view
android:layout_height="132dp"
To
android:layout_height="wrap_content"
2. Increase you linear layout height to
android:layout_width="184dp"
3. remove below pading tag from your linear layout
android:padding="6dp"
it will fix your issue.