I am using the following layouts:
<merge
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<VideoView
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ProgressBar
android:visibility="invisible"
android:id="#+id/progress"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:id="#+id/llSearch"
android:visibility="visible"
android:background="#50AAAAAA"
android:paddingTop="10dp"
android:gravity="center_vertical"
android:paddingBottom="10dp"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="72dp">
<ImageView
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:src="#drawable/abc_ic_search_api_mtrl_alpha"
android:layout_width="40dp"
android:layout_height="40dp" />
<EditText
android:textColor="#android:color/white"
android:textColorHint="#android:color/white"
android:background="#android:color/transparent"
android:visibility="visible"
android:maxLines="1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:visibility="invisible"
android:layout_marginTop="72dp"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<android.support.v7.widget.RecyclerView
android:visibility="gone"
android:layout_marginTop="72dp"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<com.myapp.custom.RevealView
android:id="#+id/reveal"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</merge>
When running the app through DDMS, I've noticed that the layout ends up being measured twice, why is this and how can I prevent overdraw?
What's also strange is that I can't figure out where the other LinearLayouts are coming from.
Measuring twice isnt overdraw. Depending on the type of layout you're using Android might need to measure it twice because of the relationship between child views require it. This can happen with layouts like LinearLayout or RelativeLayout. For exact reason you need to check the source of those, but its hardly an issue (usually).
But if you have something like a recycleview you should avoid using big nested layouts inside.
Related
I'm dealing with a weird issue and I'm kind of lost about which direction to take:
I have a fragment which is opened from several places in the app(it shows a user profile). Most of the places it's ok but in one, in particular, it has a strange behavior, the first time it's open, most views are blank, but some like the profile picture and the toolbar title are ok, if I go back and enter it again then all the views are visible as expected.
I have tried several approached to solve this, one, in particular, is to call activity.recreate() in the fragment onCreateView() which makes the views visible but has some side effects that I want to avoid and also is just a patch and not dealing directly with the problem.
Now, the most strange part to me is that if I open the screen in the layout inspector I see this:
As you can see the textviews and other elements are set, but just not visible.
One experiment I tried was giving a textview a fixed width and in that case it is visible, could this be some problem with the constraintLayout?
Any other ideas?
Thanks in advance!
EDIT:
One other thing, could the viewstubs have anything to do here?
This is the layout:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="false">
<com.google.android.material.appbar.AppBarLayout
android:id="#+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="#+id/collapsingToolBar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="0dp"
android:fitsSystemWindows="true"
app:expandedTitleGravity="top"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:titleEnabled="false">
<androidx.constraintlayout.widget.ConstraintLayout
style="#style/ProfileContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="?attr/actionBarSize"
android:elevation="0dp"
android:paddingBottom="#dimen/padding_margin_large_20">
<include
layout="#layout/common_profile_picture"
style="#style/ProfileImage"
android:id="#+id/userPicture"
android:layout_width="#dimen/round_avatar_size"
android:layout_height="#dimen/round_avatar_size"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"/>
<androidx.constraintlayout.widget.Group
android:id="#+id/follow_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible"
app:constraint_referenced_ids="user_followers_label_textview,user_followers_number_textview,follow_divider,user_following_label_textview,user_following_number_textview,sectionFollowers,sectionFollowing" />
<TextView
style="#style/ProfileFollowerTextLabel"
android:id="#+id/user_followers_label_textview"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toStartOf="#+id/user_following_label_textview"/>
<TextView
style="#style/ProfileFollowerText"
android:id="#+id/user_followers_number_textview"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#+id/user_followers_label_textview"
app:layout_constraintStart_toStartOf="#+id/user_followers_label_textview"
app:layout_constraintEnd_toEndOf="#+id/user_followers_label_textview"/>
<View
android:id="#+id/sectionFollowers"
android:layout_width="0dp"
android:layout_height="#dimen/profile_vertical_divider_height"
android:layout_marginTop="#dimen/padding_margin_large_28"
android:background="?selectableItemBackground"
android:visibility="gone"
app:layout_constraintTop_toTopOf="#+id/user_followers_label_textview"
app:layout_constraintStart_toStartOf="#+id/user_followers_label_textview"
app:layout_constraintEnd_toStartOf="#id/user_following_label_textview"
app:layout_constraintBottom_toBottomOf="#+id/user_followers_number_textview"/>
<include layout="#layout/common_divider"
android:id="#+id/follow_divider"
android:layout_width="1dp"
android:layout_height="#dimen/profile_vertical_divider_height"
android:layout_marginTop="#dimen/padding_margin_large_28"
app:layout_constraintTop_toTopOf="#+id/user_followers_label_textview"
app:layout_constraintBottom_toBottomOf="#+id/user_followers_number_textview"
app:layout_constraintStart_toEndOf="#+id/user_followers_label_textview"
app:layout_constraintEnd_toStartOf="#+id/user_following_label_textview"
app:layout_constraintHorizontal_bias="1.0"/>
<TextView
style="#style/ProfileFollowingTextLabel"
android:id="#+id/user_following_label_textview"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="#+id/user_followers_label_textview"
app:layout_constraintBottom_toBottomOf="#+id/user_followers_label_textview"
app:layout_constraintEnd_toEndOf="parent"/>
<TextView
style="#style/ProfileFollowingText"
android:id="#+id/user_following_number_textview"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#+id/user_following_label_textview"
app:layout_constraintStart_toStartOf="#+id/user_following_label_textview"
app:layout_constraintEnd_toEndOf="#+id/user_following_label_textview"/>
<View
android:id="#+id/sectionFollowing"
android:layout_width="0dp"
android:layout_height="#dimen/profile_vertical_divider_height"
android:layout_marginTop="#dimen/padding_margin_large_28"
android:background="?selectableItemBackground"
android:visibility="gone"
app:layout_constraintTop_toTopOf="#+id/user_followers_label_textview"
app:layout_constraintStart_toStartOf="#+id/user_following_label_textview"
app:layout_constraintEnd_toEndOf="#id/user_following_label_textview"
app:layout_constraintBottom_toBottomOf="#+id/user_following_number_textview"/>
<ViewStub
style="#style/ProfileAction"
android:id="#+id/profileaction_viewstub"
android:inflatedId="#+id/profileaction_viewstub"
android:layout_width="#dimen/profile_action_width"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="#+id/user_following_number_textview"
app:layout_constraintStart_toStartOf="#+id/user_followers_label_textview"/>
<TextView
style="#style/ProfileName"
android:id="#+id/user_fullname_textview"
android:layout_width="0dp"
android:layout_height="wrap_content"
tools:text="#string/placeholder"
android:drawablePadding="#dimen/padding_margin_small_4"
app:layout_constraintTop_toBottomOf="#+id/userPicture"
app:layout_constraintBottom_toTopOf="#+id/donation_list_label_textview"
app:layout_constraintVertical_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"/>
<TextView
android:id="#+id/userTitleTextView"
style="#style/ProfileTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:visibility="gone"
app:layout_constraintStart_toStartOf="#+id/user_fullname_textview"
app:layout_constraintTop_toBottomOf="#+id/user_fullname_textview" />
<androidx.emoji.widget.EmojiAppCompatTextView
style="#style/ProfileDesc"
android:id="#+id/user_description_textview"
android:layout_width="0dp"
android:layout_height="wrap_content"
tools:text="#string/placeholderLong"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#+id/userTitleTextView"/>
<TextView
android:id="#+id/userWebSiteTextView"
style="#style/ProfileWebSite"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:autoLink="web"
android:visibility="invisible"
app:layout_constraintStart_toStartOf="#+id/user_fullname_textview"
app:layout_constraintTop_toBottomOf="#+id/user_description_textview" />
<androidx.constraintlayout.widget.Group
android:id="#+id/donating_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
app:constraint_referenced_ids="donation_list_label_textview,donating_arrow_imageview,donationList,donationDivider" />
<include
android:id="#+id/donationDivider"
layout="#layout/common_divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginStart="#dimen/padding_margin_medium_16"
android:layout_marginTop="#dimen/padding_margin_medium_16"
android:layout_marginEnd="#dimen/padding_margin_medium_16"
android:layout_marginBottom="#dimen/padding_margin_medium_16"
app:layout_constraintBottom_toTopOf="#+id/donation_list_label_textview"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/userWebSiteTextView" />
<TextView
android:id="#+id/donation_list_label_textview"
style="#style/ProfileDonatingLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/profile_donating"
app:layout_constraintStart_toStartOf="#+id/user_fullname_textview"
app:layout_constraintTop_toBottomOf="#+id/donationDivider" />
<ImageView
android:id="#+id/donating_arrow_imageview"
android:layout_width="#dimen/profile_arrow_size"
android:layout_height="#dimen/profile_arrow_size"
app:srcCompat="#drawable/ic_chevron_accent_right"
android:tint="?iconColorSelected"
app:layout_constraintBottom_toBottomOf="#+id/donation_list_label_textview"
app:layout_constraintStart_toEndOf="#+id/donation_list_label_textview"
app:layout_constraintTop_toTopOf="#+id/donation_list_label_textview"
app:layout_constraintVertical_bias="0.75" />
<TextView
android:id="#+id/donationList"
style="#style/TextValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="start"
android:paddingTop="#dimen/padding_margin_small_4"
android:paddingBottom="#dimen/padding_margin_large_30"
app:layout_constraintStart_toStartOf="#+id/user_fullname_textview"
app:layout_constraintTop_toBottomOf="#+id/donation_list_label_textview" />
</androidx.constraintlayout.widget.ConstraintLayout>
<include layout="#layout/common_divider"
android:id="#+id/postsDivider"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_gravity="bottom"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
android:layout_marginStart="#dimen/padding_margin_medium_16"
android:layout_marginEnd="#dimen/padding_margin_medium_16"
android:layout_marginBottom="#dimen/padding_margin_medium_18"/>
<include layout="#layout/common_toolbar_back"
android:id="#+id/profileToolbar"/>
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<FrameLayout
android:id="#+id/tabContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
<TextView
android:id="#+id/private_profile_textview"
style="#style/TextValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|bottom"
android:layout_marginBottom="#dimen/profile_private_label_bottom_margin"
android:text="#string/profile_private"
android:visibility="gone" />
<androidx.core.widget.ContentLoadingProgressBar
android:id="#+id/postsLoadingProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:theme="?android:attr/progressBarStyleLarge"
android:visibility="gone" />
<include layout="#layout/loader"
android:id="#+id/profileLoader"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
The first thing you want to do is check color of the font that you are using. the second is the theme that you are using after that in your fragment xmls root tag put color="white" and clickable is true.
This problem is occurred mostly due to the delay and high processing , like your are loading something heavy on your views or overlapping some containers and these are being skipped.
Easy one is just put a background color to this fragment's root container.
Try to remove overlapping of layouts/views because GPU overrides are increasing and rendering becomes slow.
I think the problem must be in layout file. As you said when you open layout file the textviews and other elements are set, but just not visible.
That's what troubling the fragment while inflating the views when you open it first time.
Try:
1.Check your style.xml and layout file again
2.Debug by replacing the code in layout with simple views
I am trying to resolve a Layout Margin issue, where after I run the app on the emulator the Status Text doesn't appear where I intend it to be.
Attached is the full layout code. How can I improve the code to mitigate this issue in the future?
<?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/colorPrimary"
tools:context=".SettingsActivity">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/settings_profile_image"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:src="#drawable/default_profile" />
<TextView
android:id="#+id/settings_username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="244dp"
android:text="#string/user_name"
android:textColor="#android:color/background_light"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:id="#+id/settings_user_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:layout_marginBottom="260dp"
android:text="#string/user_profile_status"
android:textColor="#android:color/background_light"
android:textSize="18sp" />
</RelativeLayout>
What am I missing?
In the 1st place, you may want to try the constraint layout introduced by android as part of android material design which is aimed at avoiding all the overhead of nesting views. In constraint layout views can be dragged and drooped and they can be assigned margins in the multiples of 8. It is highly suggested to use constraint layouts as opposed to the old nesting of layouts.
if you want the status below user name, just use
android:layout_below="#+id/settings_username"
In your current layout, marginTop is useless, vertical position is decided by
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="260dp"
It is better to use ContraintLayout, which will remove all unused attributes (e.g, if margin is useless, margin attribute is automatically removed).
Try this You just have to remove android:layout_marginBottom="260dp" and android:layout_alignParentBottom="true" and Add android:layout_below="#+id/settings_username" in settings_user_status
<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/colorPrimary"
tools:context=".SettingsActivity">
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/settings_profile_image"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:src="#drawable/default_profile" />
<TextView
android:id="#+id/settings_username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="244dp"
android:text="#string/user_name"
android:textColor="#android:color/background_light"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:id="#+id/settings_user_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:layout_below="#+id/settings_username"
android:text="#string/user_profile_status"
android:textColor="#android:color/background_light"
android:textSize="18sp" />
</RelativeLayout>
I am trying to place a relativelayout under another (with recyclerview in it) within an activity layout container.
What I'd like to get is to have the action bar, then below a relativelayout with header (showing a spacer and 2 textviews), and below again another relativelayout that will host cards from a recyclerview.
This is the image of the wanted design:
What I get instead is this:
I am using the following xml (but tried many others)
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:theme="#style/Theme.AppCompat.Light">
<RelativeLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
tools:ignore="UselessParent">
<ImageView
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_centerInParent="true"
android:contentDescription="image"
android:scaleType="centerCrop"
android:src="#drawable/category_detail_1" />
<TextView
android:id="#+id/spacer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingEnd="5dp"
android:paddingStart="5dp"
android:text=""
android:textColor="#fff"
android:textSize="25sp" />
<TextView
android:id="#+id/sub_header_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/spacer"
android:background="#66555555"
android:paddingEnd="5dp"
android:paddingStart="5dp"
android:text=""
android:textColor="#fff"
android:textSize="30sp"
android:textStyle="bold" />
<TextView
android:id="#+id/sub_header_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/sub_header_title"
android:background="#66555555"
android:paddingEnd="5dp"
android:paddingStart="5dp"
android:text=""
android:textColor="#fff"
android:textSize="20sp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/button_container"
android:layout_width="395dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/header"
tools:ignore="UselessParent">
<android.support.v4.widget.Space
android:layout_width="#dimen/default_spacing_small"
android:layout_height="#dimen/default_spacing_small" />
</RelativeLayout>
</android.support.constraint.ConstraintLayout>
I tried to put the second RelativeLayout nested as a child of the first one with no luck.
The Android Studio preview shows the design well formatted but after build the card list overlaps the header. Well formatted apart from the unknown line/constraint I do not know how to remove. It constraints the second relativelayout to the top.
What am I missing?
Any help is appreciated.
Use FrameLayout instead of android.support.constraint.ConstraintLayout
Or try with LinearLayout
As part of the on-boarding for my app, I have a series of translucent overlays that highlight the UI. Each one is a LinearLayout, initially invisible (actually "gone"), that I make visible in turn. I am having a very tough time getting one of these to display correctly on both tablets and phones, in both portrait and landscape. I can tune it to work on the phone, but then it doesn't display well on tablet-portrait.
The images here are set up to work well on 10" tablets in portrait, and they work for 7" tablets and phones in portrait, but not in landscape. In the images below, I would like the arrows (two ImageViews) to resize as needed to make room for the text. However, the Layout seems to give priority to the ImageViews no matter what I do.
(Note that I do realize I could make this work, in a way, with a RelativeLayout, however, I cannot get the translucent backgrounds to work, filling the screen, using a RelativeLayout, as far as I know.)
My question in brief: Is there a way to make LinearLayout prioritize the TextViews, giving them enough space, and resizing the ImageViews to fit the rest?
Here is a good layout (10" tablet, portrait, shown at reduced scale):
Here is a bad one with some of the text cut off (10" tablet, landscape, reduced scale):
Here is another bad one (phone):
I don't have a screenshot of the other tuning, but it displayed big arrows and no central "Tap to Continue" button.
Here is my current XML:
<RelativeLayout
android:id="#+id/main_holder"
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">
<LinearLayout
android:id="#+id/intro3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone"
android:onClick="introClicked"
android:clickable="true">
<LinearLayout
android:id="#+id/intro3_top"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="top|center_horizontal"
android:orientation="vertical"
android:gravity="top|center_horizontal">
<TextView
android:id="#+id/textViewIntro3_1"
fontPath="fonts/AsCuteAs...Heavy.ttf"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Swipe up to mark a spark completed."
android:layout_gravity="center_horizontal|top"
android:gravity="center"
android:layout_weight="1"
android:paddingBottom="5dp"
android:background="#C5000000"
android:textColor="#fff6c3"
android:textSize="30sp"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|bottom"
android:adjustViewBounds="false"
android:background="#drawable/grad_bottom"
android:padding="10dp"
android:layout_weight="1"
android:scaleType="fitCenter"
android:src="#drawable/arrow_up"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:orientation="vertical"
android:layout_weight="0"
android:background="#85000000"
android:gravity="center">
<TextView
android:id="#+id/button_intro3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:alpha="0"
android:background="#drawable/roundrect"
android:onClick="introClicked"
android:padding="10dp"
android:text="Tap to Continue"
android:clickable="true"
android:enabled="true"
android:textColor="#FFFFF6C3"
android:textSize="24sp"/>
</LinearLayout>
<LinearLayout
android:id="#+id/intro3_bottom"
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:layout_weight="1"
android:layout_gravity="bottom|center_horizontal"
android:gravity="bottom|center_horizontal">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|bottom"
android:adjustViewBounds="false"
android:background="#drawable/grad_top"
android:layout_weight="1"
android:padding="10dp"
android:scaleType="fitCenter"
android:src="#drawable/arrow_down"/>
<TextView
android:id="#+id/textViewIntro3_2"
fontPath="fonts/AsCuteAs...Heavy.ttf"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Swipe down to reject.\n "
android:layout_gravity="center_horizontal|bottom"
android:gravity="center"
android:layout_weight="1"
android:paddingBottom="0dp"
android:background="#C5000000"
android:textColor="#fff6c3"
android:textSize="30sp"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
There're several possible way of doing it. I've updated your layout a bit, so now it should meet your expectations:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="#+id/main_holder"
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">
<RelativeLayout
android:id="#+id/intro3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
android:onClick="introClicked"
android:clickable="true">
<TextView
android:id="#+id/textViewIntro3_1"
fontPath="fonts/AsCuteAs...Heavy.ttf"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Swipe up to mark a spark completed."
android:gravity="center"
android:layout_alignParentTop="true"
android:paddingBottom="5dp"
android:background="#C5000000"
android:textColor="#fff6c3"
android:textSize="30sp"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/button_intro3"
android:layout_below="#+id/textViewIntro3_1"
android:adjustViewBounds="false"
android:background="#drawable/grad_bottom"
android:padding="10dp"
android:scaleType="fitCenter"
android:src="#drawable/arrow_up"/>
<TextView
android:id="#+id/button_intro3"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:alpha="0"
android:background="#drawable/roundrect"
android:onClick="introClicked"
android:padding="10dp"
android:text="Tap to Continue"
android:clickable="true"
android:enabled="true"
android:textColor="#FFFFF6C3"
android:textSize="24sp"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="false"
android:background="#drawable/grad_top"
android:layout_below="#+id/button_intro3"
android:layout_above="#+id/textViewIntro3_2"
android:padding="10dp"
android:scaleType="fitCenter"
android:src="#drawable/arrow_down"/>
<TextView
android:id="#+id/textViewIntro3_2"
fontPath="fonts/AsCuteAs...Heavy.ttf"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Swipe down to reject.\n "
android:gravity="center"
android:layout_alignParentBottom="true"
android:paddingBottom="0dp"
android:background="#C5000000"
android:textColor="#fff6c3"
android:textSize="30sp"/>
</RelativeLayout>
</RelativeLayout>
What I did here is to rewrite the layout with RelativeLayout instead of LinearLayouts. It suits better here, in my humble opinion.
I hope, it helps.
I have a layout in which a button is aligned at the bottom of the RelativeLayout as in below code :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="250dp"
android:background="#color/background_material_light"
android:layout_height="match_parent">
<View
android:layout_alignParentLeft="true"
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#color/strokeColor"/>
<RelativeLayout
android:id="#+id/rlHeaderFilter"
android:layout_width="match_parent"
android:layout_height="#dimen/abc_action_bar_default_height_material">
<View
android:id="#+id/separator"
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#color/strokeColor"/>
<TextView
android:background="#color/actionbar_background"
android:id="#+id/tvFilterText"
style="#style/textStyleHeading2"
android:layout_toRightOf="#+id/separator"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:gravity="center"
android:textColor="#color/white"
android:text="Filter Search" />
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:src="#drawable/refresh"
android:id="#+id/resetLeadsFilter"
android:contentDescription="#string/emptyString"
android:layout_centerVertical="true"
android:padding="6dp"/>
</RelativeLayout>
<TextView
android:layout_below="#+id/rlHeaderFilter"
android:layout_marginTop="10dp"
android:id="#+id/tvBudgetFromFilter"
style="#style/textSpinnerStyleHeading"
android:layout_margin="8dp"
android:hint="Budget From"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:layout_below="#+id/tvBudgetFromFilter"
android:layout_marginTop="10dp"
android:id="#+id/tvBudgetToFilter"
style="#style/textSpinnerStyleHeading"
android:layout_margin="8dp"
android:hint="Budget To"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<include
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:layout_below="#+id/tvBudgetToFilter"
android:id="#+id/sourceLayout"
layout="#layout/source_layout" />
<include
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/statusLayout"
android:layout_margin="8dp"
android:layout_below="#+id/sourceLayout"
layout="#layout/status_layout" />
<Button
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
android:layout_marginTop="10dp"
android:textColor="#color/white"
android:background="#color/actionbar_background"
android:text="SEARCH"
android:id="#+id/bFilterLeads"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
I can see the button at the bottom of the layout as shown in the screenshot .It displays like this in pre Lollipop devices(below < 5.0 devices) :
But in Lollipop the button at the bottom does not appear as shown in following screenshot :
I am not able to get the reason for that Please help me out . Thanks in advance .
I have solved my problem ! In fact, the LinearLayout was behind the navigationBar. To fix it, just add this line to the Activity (after setContentView();)
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
I'm not sure why the layout behaves differently between Lollipop/pre-Lollipop (unless there's some other piece that's not shown). I will point out though that I don't think layoutGravity is valid for views within a RelativeLayout -- that's something you'd use with a LinearLayout. I'd first remove that property and see how it behaves on pre-Lollipop, and then see about correcting the layout once that's done. It could be that layoutGravity is causing some sort of incorrect behavior pre-Lollipop.