I'm making a design in android using simple LinearLayout I create a TextView inside CardView when I enter long text inside TextView it hides some of the text, why this is happening? Check below image
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="#dimen/universal_padding"> <!-- 8dp -->
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical">
<ImageView
android:id="#+id/ivCommentProfilePic"
android:layout_width="#dimen/card_profile_pic_width_height"
android:layout_height="#dimen/card_profile_pic_width_height"
app:srcCompat="#drawable/circular_photo" />
<ImageView
android:id="#+id/ivCommentUserBadge"
android:layout_width="#dimen/badge_width_height"
android:layout_height="#dimen/badge_width_height"
android:layout_marginTop="10dp"
android:layout_marginLeft="-10dp"
android:layout_marginStart="-10dp"
app:srcCompat="#drawable/shap_circle_badge" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="4dp"
android:layout_marginStart="4dp"
android:layout_marginRight="8dp"
android:layout_marginEnd="8dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1">
<TextView
android:id="#+id/tvCommentUserFullName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:textStyle="bold"
android:textColor="#color/colorPrimaryText"
android:text="Azeem Haider" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/colorSecondaryText"
android:text=" - 2d"/>
</LinearLayout>
<TextView
android:id="#+id/tvCommentText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#color/colorSecondaryText"
android:text="This is a comment for testing purpose This is a comment for testing purpose This is a comment for testing purpose"
/>
</LinearLayout>
</LinearLayout>
Try this
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical">
<ImageView
android:id="#+id/ivCommentProfilePic"
android:layout_width="96dp"
android:layout_height="96dp"
app:srcCompat="#drawable/kid" />
<ImageView
android:id="#+id/ivCommentUserBadge"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_marginLeft="-10dp"
android:layout_marginStart="-10dp"
android:layout_marginTop="10dp"
app:srcCompat="#drawable/ic_online" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="8dp"
android:layout_marginStart="4dp"
android:layout_weight="1"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1">
<TextView
android:id="#+id/tvCommentUserFullName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="Azeem Haider"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" - 2d" />
</LinearLayout>
<TextView
android:id="#+id/tvCommentText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="This is a comment for testing purpose This is a comment for testing purpose This is a comment for testing purpose" />
</LinearLayout>
</LinearLayout>
OUTPUT
Related
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 have this layout of fragment:
<LinearLayout
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"
tools:context="fragments.FrgLogin"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="10dp">
<ImageView
android:id="#+id/logoFragmentLogin"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:layout_gravity="center_horizontal"
android:layout_margin="20dp"
android:src="#drawable/logo_erp24h"
android:transitionName="logoTransition" />
<LinearLayout
android:id="#+id/loginLinearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="#font/proxima_nova"
android:gravity="center"
android:text="#string/bemVindo"
android:textColor="#color/black"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="#font/proxima_nova"
android:gravity="center"
android:text="#string/instrucaoLogin"
android:textColor="#color/gray"
android:textSize="15sp"
android:textStyle="bold" />
<LinearLayout
android:id="#+id/linearLayoutTwo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="20dp"
android:paddingLeft="50dp"
android:paddingRight="50dp"
android:paddingTop="20dp">
<EditText
android:id="#+id/usernameEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="#font/proxima_nova"
android:hint="#string/usuario"
android:textIsSelectable="true"
android:textColor="#color/gray"
android:textColorHint="#color/light_gray"
android:theme="#style/loginFields" />
<android.support.design.widget.TextInputLayout
android:id="#+id/etPasswordLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:hintEnabled="false"
app:passwordToggleEnabled="true"
app:passwordToggleTint="#color/gray">
<android.support.design.widget.TextInputEditText
android:id="#+id/passwordEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fontFamily="#font/proxima_nova"
android:hint="#string/senha"
android:inputType="textPassword"
android:textColor="#color/gray"
android:textColorHint="#color/light_gray"
android:theme="#style/loginFields" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/loginEnterButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#drawable/blue_background"
android:clickable="true"
android:padding="6dp">
<ImageView
android:id="#+id/loginEnterImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#mipmap/ic_right_arrow" />
<ProgressBar
android:id="#+id/loginEnterProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminateTint="#color/white"
android:visibility="invisible" />
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:fontFamily="#font/proxima_nova"
android:text="#string/entrar"
android:textColor="#color/primary"
android:textSize="20sp"
android:textStyle="bold|italic" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
When a digit a text in username and password fields, the cursor accompanies the text, but nothing appear. This fragment is load inside a Acitivty on a Frame Layout. This bug happens only on Android Lollipop device, on emulator and real smartphone;
I can select text and copy, cut, paste, but continues invisible
Please help me !!
Methods used on Fragment class with setVisibility not working
Hi I have problem with apportionment of layouts in android xml.
The master layout is Relative layout. Whole screen is occupied by ExoPlayer and these three elements are placed over the player.
On the picture blue is linear layout and it should take 1/3 of the screen height.
The green layout(linear) should takes 1/9 of the screen height and the red linear should also takes 1/3 of the screen.
I have tried to use weights but unfortunately my approach doesn't work and I am getting warning that could affect performance of the application.
Please, can you assist me to achieve this design?
Thanks
EDIT:
<?xml version="1.0" encoding="utf-8"?>
<data>
<import type="android.view.View" />
<import
alias="position" />
<variable
name="vm"/>
</data>
<RelativeLayout
android:id="#+id/master_layoout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.exoplayer2.ui.SimpleExoPlayerView
android:id="#+id/player_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:layoutMode="#{vm.fullScreen}"
android:player="#{vm.player}"
app:use_controller="false" />
<!-- STARTof menu layout-->
<LinearLayout
android:layout_alignParentTop="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="9">
<View
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"/>
<LinearLayout
android:id="#+id/menu_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/info"
android:layout_alignParentEnd="true"
android:background="#000000"
android:orientation="vertical"
android:paddingLeft="1dp"
android:paddingRight="1dp"
android:paddingTop="1dp"
android:visibility="#{vm.menuVisibility}"
android:layout_weight="3">
<LinearLayout
android:id="#+id/details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#{vm.getSelectedCurrentOption == 0 ? #color/selectedMenuItem : #color/unselectedMenuItem }"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="15dp"
android:src="#drawable/mockup_icon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginRight="20dp"
android:fontFamily="sens-serif"
android:paddingEnd="10dp"
android:text="DETALJNO"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:id="#+id/favorites"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="1dp"
android:layout_marginTop="1dp"
android:background="#{vm.getSelectedCurrentOption == 1 ? #color/selectedMenuItem : #color/unselectedMenuItem }"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="15dp"
android:src="#drawable/mockup_icon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginRight="20dp"
android:fontFamily="sens-serif"
android:text="OMILJENI"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:id="#+id/record"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#{vm.getSelectedCurrentOption == 2 ? #color/selectedMenuItem : #color/unselectedMenuItem }"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="15dp"
android:src="#drawable/mockup_icon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginEnd="20dp"
android:fontFamily="sens-serif"
android:text="VRATI NA POCETAK"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:id="#+id/remind_me"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="1dp"
android:layout_marginTop="1dp"
android:background="#{vm.getSelectedCurrentOption == 3 ? #color/selectedMenuItem : #color/unselectedMenuItem }"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="15dp"
android:src="#drawable/mockup_icon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginEnd="20dp"
android:fontFamily="sens-serif"
android:text="SNIMI"
android:textColor="#000000" />
</LinearLayout>
<LinearLayout
android:id="#+id/return_to_begin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#{vm.getSelectedCurrentOption == 4 ? #color/selectedMenuItem : #color/unselectedMenuItem }"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="15dp"
android:src="#drawable/mockup_icon" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginEnd="20dp"
android:fontFamily="sens-serif"
android:paddingEnd="10dp"
android:text="PODSETI ME"
android:textColor="#000000" />
</LinearLayout>
<!-- end of menu layout-->
</LinearLayout>
<LinearLayout
android:id="#+id/info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical"
android:layout_weight="1">
<RelativeLayout
android:id="#+id/media_control_view"
android:layout_width="match_parent"
android:layout_height="58dp"
android:background="#96000000"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:visibility="#{vm.getMediaControlView==true ? View.VISIBLE : View.INVISIBLE}">
<ImageView
android:id="#+id/channel_icon"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_gravity="center_vertical"
android:src="#{vm.icon}" />
<TextView
android:id="#+id/media_title"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:layout_marginTop="12dp"
android:layout_toEndOf="#+id/channel_icon"
android:fontFamily="sens-serif"
android:maxLength="50"
android:padding="12dp"
android:text="#{vm.getTitle}"
android:textColor="#f15a29"
android:textSize="12sp" />
<ImageView
android:id="#+id/play_pause_icon"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:layout_toStartOf="#+id/animate_progress_bar"
android:src="#drawable/play_icon" />
<com.daasuu.ahp.AnimateHorizontalProgressBar
android:id="#+id/animate_progress_bar"
android:layout_width="300dp"
android:layout_height="2dp"
android:layout_centerVertical="true"
android:layout_gravity="center_vertical"
android:layout_toStartOf="#+id/remaining_time"
android:max="#{vm.maxProgress}"
android:paddingStart="10dp"
android:progress="#{vm.progress}"
app:ahp_backgroundColor="#C0C0C0"
app:ahp_progressColor="#f15a29" />
<TextView
android:id="#+id/remaining_time"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:layout_marginEnd="25dp"
android:layout_marginTop="12dp"
android:layout_toStartOf="#+id/icon_info"
android:fontFamily="sens-serif"
android:padding="12dp"
android:text="#{vm.times}"
android:textColor="#D3D3D3" />
<ImageView
android:id="#+id/icon_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:layout_toStartOf="#+id/icon_menu"
android:src="#drawable/icon_info" />
<ImageView
android:id="#+id/icon_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:layout_marginEnd="5dp"
android:layout_marginStart="10dp"
android:src="#drawable/icon_menu" />
</RelativeLayout>
<LinearLayout
android:id="#+id/additional_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:background="#80000000"
android:orientation="horizontal"
android:visibility="#{vm.infoVisibility}"
android:weightSum="90"
android:layout_weight="3">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/cover_image" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:layout_marginTop="15dp"
android:layout_weight="60"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sens-serif"
android:text="The Gardian of the Galaxy Vol.2"
android:textColor="#color/primary_orange"
android:textSize="25sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sens-serif"
android:text="19:00 - 21:00 | 2017 | Science fiction film/Action | 2h 18m\n"
android:textColor="#color/epg_event_layout_text" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sens-serif"
android:text="Peter Quill and his fellow Guardians are hired by a power-\nful alien race, the Sovereign, to protect their precious bat-\nteries from invaders. When it is discovered that Rocket\nhas stolen the items they were sent to guard, the Sover-\n"
android:textColor="#color/epg_event_layout_text" />
</LinearLayout>
<View
android:layout_width="3dp"
android:layout_height="match_parent"
android:layout_marginBottom="15dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="15dp"
android:background="#FFFFFF" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:fontFamily="sens-serif"
android:text="Rezija:\nMajkl Kejn\n\nGLUMCI:\nChris Pratt, Zoe\nSaldana, Dave Bau-\ntista, Bradley\nCooper, Vin Diesel,\nMichael Rooke\n"
android:textColor="#color/epg_event_layout_text" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
Layout Weight works only with LinearLayout
Use weights for your views and test them. The example given in the documentation is pretty self-explanatory.
So in my program i have a layout implemented in which i want the image to alignTop of the parent. I used to exact same layout code for another activity (with minor changes) and it works perfectly but when using it in this activity it does not. My image still aligns to the center fo the view. Here is the layout xml
<?xml version="1.0" encoding="utf-8"?>
<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"
android:background="#color/darkGray"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.intellidev.fuzionvapor.HomeDetails"
tools:showIn="#layout/activity_home_details">
<ImageView
android:id="#+id/homeDetailsActivityImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:scaleType="fitCenter" />
<TextView
android:id="#+id/homeDetailsActivityTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/homeDetailsActivityImage"
android:textColor="#color/white"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="#+id/homeDetailsActivityPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/homeDetailsActivityImage"
android:textColor="#color/fuzionRed"
android:textSize="20sp"
android:textStyle="bold" />
<View
android:id="#+id/homeDetailsActivityRuler"
android:layout_width="fill_parent"
android:layout_height="1dip"
android:layout_below="#+id/homeDetailsActivityTitle"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:background="#color/white" />
<TextView
android:id="#+id/homeDetailsActivityDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/homeDetailsActivityRuler"
android:textColor="#color/white"
android:textSize="15sp" />
<LinearLayout
android:id="#+id/homeDetailsFooter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/homeDetailsActivityButton"
android:layout_centerHorizontal="true"
android:orientation="horizontal">
<fr.ganfra.materialspinner.MaterialSpinner
android:id="#+id/homeDetailsActivitySizeSpinner"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_margin="1dp"
android:layout_weight="1"
app:ms_arrowColor="#color/fuzionRed"
app:ms_arrowSize="16dp"
app:ms_baseColor="#color/fuzionRed"
app:ms_enableFloatingLabel="true"
app:ms_floatingLabelColor="#color/fuzionRed"
app:ms_floatingLabelText="#string/sizeFloatingLabel"
app:ms_highlightColor="#color/fuzionRed"
app:ms_hintColor="#color/fuzionRed"
app:ms_hint="Size"
app:ms_multiline="false"
app:ms_thickness="1dp" />
<fr.ganfra.materialspinner.MaterialSpinner
android:id="#+id/homeDetailsActivityNicotineSpinner"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:layout_weight="1"
app:ms_arrowColor="#color/fuzionRed"
app:ms_arrowSize="16dp"
app:ms_baseColor="#color/fuzionRed"
app:ms_enableFloatingLabel="true"
app:ms_floatingLabelColor="#color/fuzionRed"
app:ms_floatingLabelText="#string/nicotineFloatingLabel"
app:ms_highlightColor="#color/fuzionRed"
app:ms_hintColor="#color/fuzionRed"
app:ms_multiline="false"
app:ms_hint="Nicotine"
app:ms_thickness="1dp" />
</LinearLayout>
<Button
android:id="#+id/homeDetailsActivityButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:background="#color/fuzionRed"
android:text="Add To Cart"
android:textAlignment="center"
android:textColor="#color/white"
android:textSize="25sp"
android:textStyle="bold" />
</RelativeLayout>
change
<ImageView
android:id="#+id/homeDetailsActivityImage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:scaleType="fitCenter" />
to
<ImageView
android:id="#+id/homeDetailsActivityImage"
android:layout_width="match_parent"
android:layout_alignParentTop="true"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:adjustViewBounds="true"
android:scaleType="fitStart" />
I am trying to make an android view where there is an image at the top, with text at the bottom, similar to the Android now cards.
I'm having issues taking the "command" buttons and aligning them below all the text, ideally separated by a HR line.
Here is the code I've been working with, and unable to make it look like the android Now cards -
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="5dp"
card_view:cardCornerRadius="2dp"
card_view:contentPadding="10dp">
<LinearLayout
android:id="#+id/card_view_inner_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp">
<TextView
android:textColor="#0000FF"
android:id="#+id/personaTextView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toLeftOf="#+id/image_view"
android:layout_toStartOf="#+id/image_view"
android:textAppearance="?android:textAppearanceLarge"
android:text="Some text here" />
<TextView
android:textColor="#00FFFF"
android:id="#+id/personaTextView2"
android:layout_below="#+id/personaTextView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/image_view"
android:layout_toStartOf="#+id/image_view"
android:text="Some text here" />
<ImageView
android:id="#+id/image_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:src="#android:drawable/btn_radio" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#android:color/darker_gray" />
<RelativeLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="#+id/cardAction1"
android:textColor="#00FFFF"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Action 1"
android:layout_toLeftOf="#+id/cardAction2"
style="?android:attr/borderlessButtonStyle"
/>
<Button
android:id="#+id/cardAction2"
android:textColor="#00FFFF"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Action 2"
style="?android:attr/borderlessButtonStyle"
/>
</RelativeLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
The problem I'm (now) having is that I can't get the action buttons to work
You have to add a flat button like this in your view (see this link):
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Your text"
style="?android:attr/borderlessButtonStyle"
/>
Then, of course, is up to you to design your View.
Something like this?
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="5dp"
card_view:cardCornerRadius="2dp"
card_view:contentPadding="10dp">
<LinearLayout
android:id="#+id/card_view_inner_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp">
<TextView
android:id="#+id/text_view1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toLeftOf="#+id/image_view"
android:layout_toStartOf="#+id/image_view"
android:textAppearance="?android:textAppearanceLarge"
android:text="Some text here" />
<TextView
android:id="#+id/text_view2"
android:layout_below="#+id/text_view1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toLeftOf="#+id/image_view"
android:layout_toStartOf="#+id/image_view"
android:text="Some text here" />
<ImageView
android:id="#+id/image_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:src="#android:drawable/btn_radio" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="#android:color/darker_gray" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="Some random text" />
</LinearLayout>
</android.support.v7.widget.CardView>