I've created a simple android app with webview to showcase my website, so now am trying to add FAB so users can share articles with that button. Wherever I place the code, either it crashes or just not being useful when I place inside webview because it gets scrolls, am sharing my code below, can you please help with the alignment, I want FAB to be a sticky button at the right bottom of the app.
<?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"
tools:context=".MainActivity">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="#+id/swipe"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout_behavior="#string/appbar_scrolling_view_behavior">
<WebView
android:id="#+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent">
</WebView>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<ProgressBar
android:id="#+id/progress"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
style="?android:attr/progressBarStyle"
/>
</RelativeLayout>
Can you please guide me with the correct way of doing it, after this I've to change JAVA file.
Try this,
<?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="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="75dp"
android:orientation="horizontal"
android:elevation="6dp"
android:layout_alignParentBottom="true">
<YOUR_FAB_HERE
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_marginEnd="25dp"
android:visibility="visible"
app:srcCompat="#drawable/ic_file_upload_white_24dp"
tools:ignore="VectorDrawableCompat" />
</RelativeLayout>
<--- your additional layout here ----->
</RelativeLayout>
Related
I have an app that has been running on my deivce perfectly fine for a long time. Today I decided to test it on an older device. I have an old Glaxy S4 Mini, so I loaded it up, and an entire part of my layout was missing. The missing part is a reusable layout I made, and included it in this activity. The space where it would be is not taken up by anything, it is just left empty
This is the activity layout file. Everything that is inside of include is completely missing when the app is ran.
<?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"
tools:context="com.example.eddie.songsPrimirenya.SearchActivityReg">
<include
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/search_bar_include"
layout="#layout/search_bar"
/>
<android.support.v7.widget.RecyclerView
android:id="#+id/RecyclerViewReg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_below="#+id/search_bar_include"
android:layout_margin="3dp"/>
</RelativeLayout>
and this is the layout that I was including earlier. I think it's not showing because of some compatibility issue, but I do not know what it is.
<?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:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/cardSearchReg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
card_view:cardCornerRadius="5dp"
card_view:layout_constraintBottom_toBottomOf="parent"
card_view:layout_constraintEnd_toEndOf="parent"
card_view:layout_constraintStart_toStartOf="parent"
card_view:layout_constraintTop_toTopOf="parent"
card_view:layout_constraintVertical_bias="0.0">
<RelativeLayout
android:id="#+id/LayoutAll"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="#+id/LayoutSearch"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="#+id/txtInReg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:hint="#string/search"
android:singleLine="true"
android:textColorHint="#color/textHint" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/LayoutSearchModeSelect"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/LayoutSearch"
android:layout_marginStart="3dp">
<Switch
android:id="#+id/swtSearchType"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="false"
android:text="#string/search_by_name"
android:textColorHighlight="#color/colorAccent"
android:textSize="16sp" />
</RelativeLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
</android.support.constraint.ConstraintLayout>
Here is an image of how it is supposed to look like
and this is what it ends up looking like
make your include layout match parent,it should work fine
<?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"
tools:context="com.example.eddie.songsPrimirenya.SearchActivityReg">
<include
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/search_bar_include"
layout="#layout/search_bar"
/>
<android.support.v7.widget.RecyclerView
android:id="#+id/RecyclerViewReg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_below="#+id/search_bar_include"
android:layout_margin="3dp"/>
</RelativeLayout>
Check Following Image.
![background activity content showing while opening keyboard or close. first layout goes up it take mili second to open keyboard.
Below Address field white part there is background activity content.]1
Manifest File
android:windowSoftInputMode="stateAlwaysHidden"
Here its my layout top Views. Help me to resolve this issue.
<?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"
android:id="#+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white"
android:clickable="true">
<include
android:id="#+id/top_bar"
layout="#layout/top_bar_steps_form" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/top_bar">
<FrameLayout
android:id="#+id/root_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:orientation="vertical"
android:visibility="visible">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom">
<LinearLayout
android:id="#+id/parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center|bottom"
android:orientation="vertical"
android:visibility="visible">
</LinearLayout>
</RelativeLayout>
</ScrollView>
</FrameLayout>
</RelativeLayout>
</RelativeLayout>
i was using Transparent theme Theme.AppCompat.Translucent
i just change theme and it fixed
Is there a way to use some non scrollable view when the activity has ScrollView component?
I want that my button behaves similar to the button in the question below, I want it fixed on the bottom of the UI too:
how to set a button at a fixed location on the bottom of UI?
Here's my layout code:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent ">
<FrameLayout
android:id="#+id/map_frameview"
android:layout_width="match_parent"
android:layout_height="200dp">
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="20dp">
</LinearLayout>
</LinearLayout>
</ScrollView>
Thanks in advance!
The link you have attached in your question shows how you can do it. You can use RelativeLayout for this. The idea is, you need to tell a button to stay on bottom of the screen & tell the scrollview to stay above the Button along with it's scrollable content like:
<?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="match_parent">
<Button
android:id="#+id/btnMy"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/btnMy">
<LinearLayout
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:layout_above="#id/btnMy"
android:orientation="vertical">
<FrameLayout
android:id="#+id/map_frameview"
android:layout_width="match_parent"
android:layout_height="200dp">
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="20dp">
</LinearLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
Here you can see that there is a background and above it there is a white layer on which contain are given. screenshot is of a website but i want to give that effect on my app. any help will be of great use.
You can do it like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".activity.MainActivity">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/yourBackgroudImage"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:bacground="#color/white"
android:layout_margin="20dp">
<!--your code inside white backgroud layout goes here-->
</LinearLayout>
</LinearLayout>
Just use a RelativeLayout which helps you to stack your views above each other,then provide a margin to the top layout
<?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">
<ImageView
android:src="#drawable/backgroundimage"
android:scaleType="centerCrop"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<LinearLayout
android:layout_margin="20dp"
android:background="#ffffff"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--Add Data here as required-->
</LinearLayout>
</RelativeLayout>
I have a activity_pic.xml layout which includes content_pic.xml to define the layout of my app. The activity_pic.xml is below:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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:fitsSystemWindows="true"
tools:context="com.example.olivia.myapplication.PicActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="#style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_pic" />
</android.support.design.widget.CoordinatorLayout>
content_pic.xml is
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:id="#+id/pick_image_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/button_text"/>
<ImageView
android:id="#+id/image_view"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
</LinearLayout>
When I include the line <include layout="#layout/content_pic" /> within the AppBarLayout (that is, I move it up two lines) the button appears, and all the functionality of the button works. However when I put it after that, the button does not appear, and all I can see is the 'App Bar' bit of the layout.
Ok so the picture below shows how I would like it to look (and how the design view shows content_pic.xml)
And here is what it actually looks like
However, when I put the <include layout="#layout/content_pic" /> into the AppBarLayout I can see the button, as shown in the image below.
I have tried taking the content of content_pic.xml and including it directly instead of using the include statement, this still does not appear.
I've run out of ideas here - can anyone suggest what might be going wrong?
AppBarLayout works good if you us NestedScrollView or RecyclerView
so I suggest you change your content_pic.xml TO.
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:id="#+id/pick_image_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/button_text"/>
<ImageView
android:id="#+id/image_view"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
</LinearLayout>
I hope this will Help.
EDIT
You Just need to Change your content_pic.xml to this
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
<!-- Importent -->
xmlns:app="http://schemas.android.com/apk/res-auto"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<Button
android:id="#+id/pick_image_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello" />
<ImageView
android:id="#+id/image_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>