How to set bottom edge to CardView as Fab shape in BottomAppBar? - android

I would make an insert FAB in my CardView like the one set by default in the BottomAppBar.
I changed my CardView to MaterialCardView to change the bottom edge bu setting the BottomAppBarTopEdgeTreatment
The issue is that i'm playing with the fabMargin, roundedCornerRadius, cradleVerticalOffset and fabDiameter but i can't set it's values to get the result from the native BottomAppBar inset FAB.
so which values should i set in it?
Desired behaviour would be like this (Actual picture of my BottomAppBar):
While i get this (Actual picture of my CardView):
My FAB code looks like this:
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/btnScan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:contentDescription="#string/nuovo_documento"
android:translationY="-36dp"
app:layout_anchor="#id/cardView"
app:layout_anchorGravity="bottom|center"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/cardView"
app:srcCompat="#drawable/ic_outline_qr_code_scanner"
app:tint="#color/white" />
And the code where i set the shape to the Card is the following:
val bottomAppBarTreatment = BottomAppBarTopEdgeTreatment(16f, 2f, 8f)
bottomAppBarTreatment.fabDiameter = 110f
cardView.shapeAppearanceModel = cardView.shapeAppearanceModel.toBuilder()
.setBottomEdge(bottomAppBarTreatment)
.build()

You can use something like:
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/btnScan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:translationY="24dp"
../>
and:
val bottomAppBarTopEdgeTreatment = BottomAppBarTopEdgeTreatment(
resources.getDimension(R.dimen.margin), //5dp
resources.getDimension(R.dimen.rounded_corner), //8dp
resources.getDimension(R.dimen.vertical_offset) //0dp
)
bottomAppBarTopEdgeTreatment.fabDiameter = resources.getDimension(R.dimen.diameter) //56dp
cardView.shapeAppearanceModel = cardView.shapeAppearanceModel.toBuilder()
.setTopEdge(bottomAppBarTreatment)
.build()

I'm using below code snippet to achive this result using background image like below.
XML File:
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout 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/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
tools:openDrawer="start">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent">
<RelativeLayout
android:id="#+id/rr_fab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/ll_bottom_nav"
android:layout_below="#+id/ll_top"
android:background="#android:color/transparent">
<LinearLayout
android:id="#+id/ll_last"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#android:color/transparent"
android:foreground="#android:color/transparent"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#android:color/transparent"
android:foreground="#android:color/transparent">
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/fac_home"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="#dimen/padding_10"
app:backgroundTint="#color/colorPrimary"
app:srcCompat="#mipmap/home" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
<LinearLayout
android:id="#+id/ll_bottom_nav"
android:layout_width="match_parent"
android:layout_height="#dimen/padding_50"
android:layout_alignParentBottom="true"
android:layout_centerVertical="true"
android:layout_marginTop="-25dp"
android:background="#drawable/cut_nav_full_another_grey_two"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="10"
app:layout_behavior="com.wpa3.productshopify.widget.BottomNavigationViewBehavior">
<TextView
android:id="#+id/tv_category"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2.2"
android:drawableTop="#mipmap/category"
android:gravity="center"
android:text="#string/category"
android:textColor="#color/gray71"
android:textSize="#dimen/text_size_16" />
<TextView
android:id="#+id/tv_orders"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2.5"
android:drawableTop="#mipmap/order"
android:gravity="center"
android:text="#string/track_your_order"
android:textColor="#color/gray71"
android:textSize="#dimen/text_size_16" />
<View
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#android:color/transparent" />
<TextView
android:id="#+id/tv_profile"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2.5"
android:drawableTop="#mipmap/profile"
android:gravity="center"
android:text="#string/my_account"
android:textColor="#color/gray71"
android:textSize="#dimen/text_size_16" />
<TextView
android:id="#+id/tv_more"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.8"
android:drawableTop="#mipmap/more"
android:gravity="center"
android:text="#string/more"
android:textColor="#color/gray71"
android:textSize="#dimen/text_size_16" />
</LinearLayout>
</RelativeLayout>
</androidx.drawerlayout.widget.DrawerLayout>
Background Image = https://imgur.com/a/3cOhy9E
Hope this may helps you.

Related

set transperent background for constraint layout in android

hi I have to make a view like the below image .
But when i make the parent view transperent , default background is showing like this:
a transperent view is showing behind the main view.
my xml starts like :
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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="wrap_content"
android:layout_margin="#dimen/_8sdp"
android:background="#color/red"
android:clipChildren="false"
android:clipToPadding="false">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/cl2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_50sdp"
android:background="#drawable/rounded_corner_shadow"
android:clipChildren="false"
android:clipToPadding="false"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
<FrameLayout
android:id="#+id/progressLayout_frame"
android:layout_width="#dimen/_90sdp"
android:layout_height="#dimen/_90sdp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:clickable="true"
android:visibility="visible"
app:layout_constraintBottom_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<View
android:id="#+id/bgCircle"
android:layout_width="#dimen/_70sdp"
android:layout_height="#dimen/_70sdp"
android:layout_gravity="center"
android:alpha="0.7"
android:background="#color/white"
android:visibility="visible" />
<RelativeLayout
android:id="#+id/progressLayout"
android:layout_width="#dimen/_80sdp"
android:layout_height="#dimen/_80sdp"
android:layout_gravity="center"
android:background="#android:color/transparent"
android:clickable="true"
>
<ProgressBar
android:id="#+id/progressbar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="#dimen/_80sdp"
android:layout_height="#dimen/_80sdp"
android:layout_centerHorizontal="true"
android:background="#drawable/circle_shape"
android:progressDrawable="#drawable/circular_progress_bar" />
<TextView
android:id="#+id/tvTimeCount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginTop="60dp"
android:text="00:00"
android:textColor="#FFFFFF"
android:textSize="29sp"
app:customTypeFace="roboto_light" />
how can I hide the view behind . why does this layout come ? any suggestions would be helpful . thanks in advance
To remove default background of the dialog...
Step 1:
Create a custom_dialog.xml
<androidx.constraintlayout.widget.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="wrap_content"
android:layout_marginHorizontal="#dimen/_20sdp"
android:paddingHorizontal="#dimen/_25sdp"
android:paddingVertical="#dimen/_25sdp" >
<androidx.constraintlayout.widget.Guideline
android:id="#+id/left_vertical_gl"
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.02" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/right_vertical_gl"
android:layout_width="match_parent"
android:layout_height="1dp"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.98" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/center_horizontal_gl"
android:layout_width="match_parent"
android:layout_height="1dp"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.48" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/top_horizontal_gl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.044" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/end_horizontal_gl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.90" />
<TextView
android:id="#+id/textView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/segui_black"
android:text="Are You Sure?"
android:textColor="#484A67"
android:textSize="#dimen/_24ssp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/top_horizontal_gl" />
<TextView
android:id="#+id/textView10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_2sdp"
android:layout_marginBottom="12dp"
android:fontFamily="#font/segoe"
android:gravity="center"
android:text="Are you sure you want to sign out?"
android:textColor="#484A67"
android:textSize="#dimen/_11ssp"
app:layout_constraintEnd_toStartOf="#+id/right_vertical_gl"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textView9" />
<TextView
android:id="#+id/yesTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_20sdp"
android:fontFamily="#font/segui_semi_bold"
android:padding="#dimen/_5sdp"
android:text="Yes"
android:textColor="#AD7BFF"
app:layout_constraintEnd_toStartOf="#+id/right_vertical_gl"
app:layout_constraintTop_toBottomOf="#+id/textView10" />
<TextView
android:id="#+id/noTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="#dimen/_30sdp"
android:fontFamily="#font/segoe"
android:padding="#dimen/_5sdp"
android:text="No"
android:textColor="#6D6E85"
app:layout_constraintBottom_toBottomOf="#+id/yesTv"
app:layout_constraintEnd_toStartOf="#+id/yesTv"
app:layout_constraintTop_toTopOf="#+id/yesTv"
tools:layout_editor_absoluteX="143dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
Step 2:
Go to your dialog activity
Add the below line to your dialog code
popUpDialog.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
Complete code of the dialog
private lateinit var popUpDialog: Dialog
private fun buyLifeLineDialog() {
popUpDialog.setContentView(R.layout.dialog_buy_lifelines)
popUpDialog.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
val yesTv = popUpDialog.findViewById<TextView>(R.id.yesTv);
val noTv = popUpDialog.findViewById<TextView>(R.id.noTv);
popUpDialog.show()
yesTv.setOnClickListener {
if (isCheatLl) {
mViewModel.buyCheatLifeline(index,lifeLinesPackagesModel)
}
else{
mViewModel.buyRespawnLifeline(index,lifeLinesPackagesModel)
}
popUpDialog.dismiss()
}
noTv.setOnClickListener {
popUpDialog.dismiss()
}
}
I don't know how do you display this window in your app , but I suppose that you display it as custom dialog , so the problem is that you need to add a transparent theme for your dialog to get the same design or your dialog will fill the transparent spaces with this black color or white depends on your app theme , so to solve this problem you need to add this style in your theme.xml file or style.xml
<style name="AlertDialogCustom" parent="#android:style/Theme.Dialog">
<item name="android:windowBackground">#android:color/transparent</item>
</style>
and then you create a new custom dialog in your activity like this
//Here i will create new dialog with a custom style which I added in Theme.xml
final AlertDialog dialog2 = new AlertDialog.Builder(MainActivity.this,R.style.AlertDialogCustom).create();
LayoutInflater inflater = getLayoutInflater();
//Here I added my xml file , you can replace test with your own xml file
View convertView = (View) inflater.inflate(R.layout.test, null);
dialog2.setView(convertView);
dialog2.setCancelable(false);
//Here we tell the dialog to display , you can call show() when click a button
dialog2.show();
and here it's my simple design to get a transparent background
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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="350dp"
android:layout_margin="8dp"
android:background="#android:color/transparent"
android:clipChildren="false"
android:clipToPadding="false">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/cl2"
android:layout_width="350dp"
android:layout_height="350dp"
android:layout_marginTop="50dp"
android:background="#FFFFFF"
android:clipChildren="false"
android:clipToPadding="false"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
<FrameLayout
android:id="#+id/progressLayout_frame"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:clickable="true"
android:visibility="visible"
app:layout_constraintBottom_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<View
android:id="#+id/bgCircle"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_gravity="center"
android:background="#drawable/pers_icon"
android:visibility="visible" />
<RelativeLayout
android:id="#+id/progressLayout"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_gravity="center"
android:background="#android:color/transparent"
android:clickable="true">
</RelativeLayout>
</FrameLayout>
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
tools:layout_editor_absoluteX="218dp"
tools:layout_editor_absoluteY="129dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Now this is the final result , you can make your own design

Centering Nested Relative layout in parent

I have to make (sort of) footer for empty screen. My parent layout is RelativeLayout1. Inside this layout I have ToolBar and below that is another RelativeLayout2.
Inside this RelativeLayout2 is Button and another RelativeLayout3. I made it that way, because I want to center RelativeLayout3 content in RelativeLayout2 and Button should always align bottom of the parent layout(RelativeLayout2)
I got answer for similar question before, but it doesnt always work. My problem now is that RelativeLayout3 is off-centered vertically(it's closer to the bottom).
How it should looks like
How it actually looks like
How to fix this?
Full Layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#color/colorBackground"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="#+id/toolBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/toolbar_round"
android:orientation="horizontal">
<include
android:id="#+id/toolBarContent"
layout="#layout/order_toolbar_layout" />
</android.support.v7.widget.Toolbar>
<RelativeLayout
android:id="#+id/order_complete_footer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/toolBar"
android:gravity="center"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/order_complete_image_text_layout"
android:layout_centerInParent="true"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ImageView
android:id="#+id/order_complete_image"
android:layout_width="175dp"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:src="#drawable/footer_image" />
<TextView
android:id="#+id/order_complete_text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/order_complete_image"
android:layout_marginEnd="50dp"
android:layout_marginStart="50dp"
android:layout_marginTop="-12dp"
android:gravity="center_horizontal"
android:text="#string/order_complete_screen_text1"
android:textColor="#color/colorItemMinor"
android:textStyle="bold"
android:textSize="12sp" />
<TextView
android:id="#+id/order_complete_text2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/order_complete_text1"
android:layout_marginEnd="50dp"
android:layout_marginStart="50dp"
android:gravity="center_horizontal"
android:text="#string/order_complete_screen_text2"
android:textColor="#color/colorItemMinor"
android:textSize="12sp" />
</RelativeLayout>
<Button
android:id="#+id/order_complete_continue_button"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_marginBottom="#dimen/address_creation_button_padding_TOP_BOTTOM"
android:layout_marginEnd="#dimen/address_creation_button_padding_START_END"
android:layout_marginStart="#dimen/address_creation_button_padding_START_END"
android:layout_marginTop="#dimen/address_creation_button_padding_TOP_BOTTOM"
android:background="#drawable/login_button_background_void"
android:text="#string/order_complete_screen_button_label"
android:textAppearance="#style/VoidLoginButtonTextAppearance" />
</RelativeLayout>
</RelativeLayout>
If I understood correctly, you should add the following to your order_complete_image_text_layout.
android:layout_above="#id/order_complete_continue_button"
#JanStoltman

Setting TextView's left and right doesn't work with ellipsize

When I try to set TextView's left and right property, the ellipsize property doesn't work. It just clips the object.
I am setting the left and right like this:
textView.left = textMargin
textView.right = Math.min(view.measuredWidth - textMargin, margin)
It has already applied ellipsize property. But, it doesn't work.
I can see the bounds are clipped:
UPDATE: It's a toolbar's default title textview. I am accessing it with reflection.
val field = Toolbar::class.java.getDeclaredField("mTitleTextView")
field.isAccessible = true
val textView: TextView? = field.get(toolbar) as TextView?
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar_app"
android:layout_width="fill_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/colorPrimary"
app:contentInsetEnd="0dp"
app:contentInsetLeft="0dp"
app:contentInsetRight="0dp"
app:contentInsetStart="0dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center|center_horizontal"
android:orientation="horizontal">
<ImageView
android:id="#+id/iv_first"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:src="#mipmap/ic_launcher"
android:visibility="visible" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginTop="3dp"
android:layout_toLeftOf="#+id/iv_search_second"
android:layout_toRightOf="#+id/iv_first"
android:ellipsize="end"
android:gravity="center"
android:lines="1"
android:text="text Status carfsadffaf"
android:textColor="#android:color/white"
android:textSize="16sp" />
<ImageView
android:id="#+id/iv_search_second"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/iv_search_first"
android:src="#mipmap/ic_launcher"
android:visibility="visible" />
<ImageView
android:id="#+id/iv_search_first"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:src="#mipmap/ic_launcher"
android:visibility="visible" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>

Can't convert PercentRelative Layout to Linear Layout

Basicly i created all my layouts with a library that is already deprecated (PercentRelativeLayout) everything works well except that i have this layout inside a ScrollView, and the scroll doesn't work on all devices.
I read some topics about it and seems the issue is with the Percent Library.
So i need to move on and construct the Lienar Layout example, i tried to construct my layout with the current Layout that i have but everything got buggy, the spaces between the elements are never the same as i had with the percent.
Basicly what i need is this:
The elements are top down -> toolbar -> thumbnail -> recycle view(this one just has a unique image -> details about this foto.
I have more details about it, but if i can construct this example its fine.
so my xml that i current have is this:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.percent.PercentRelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.FloatingActionButton
android:id="#+id/fab"
app:srcCompat="#android:drawable/ic_menu_camera"
android:elevation="2dp"
app:layout_widthPercent="90%"
app:layout_heightPercent="10%"
app:layout_marginTopPercent="90%"
app:layout_marginLeftPercent="80%"
app:backgroundTint="#f1c40f"
android:onClick="capture"/>
<include
layout="#layout/custom_toolbar"
android:id="#+id/my_toolbar"
app:layout_widthPercent="100%"
app:layout_heightPercent="8%"
app:layout_marginTopPercent="0%"
app:layout_marginLeftPercent="0%"/>
<com.example.afcosta.inesctec.pt.android.Helpers.OpenSansMedium
android:id="#+id/SpecieName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/nephritis"
android:textSize="14dp"
app:layout_widthPercent="60%"
app:layout_heightPercent="5%"
app:layout_marginTopPercent="85%"
app:layout_marginLeftPercent="30%"/>
<com.example.afcosta.inesctec.pt.android.Helpers.OpenSansMedium
android:id="#+id/GenreName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="genrePressed"
android:textColor="#color/nephritis"
android:textSize="14dp"
app:layout_widthPercent="60%"
app:layout_heightPercent="5%"
app:layout_marginTopPercent="95%"
app:layout_marginLeftPercent="30%"/>
<com.example.afcosta.inesctec.pt.android.Helpers.OpenSansMedium
android:id="#+id/FamilyName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="familyPressed"
android:textColor="#color/nephritis"
android:textSize="14dp"
app:layout_widthPercent="60%"
app:layout_heightPercent="5%"
app:layout_marginTopPercent="105%"
app:layout_marginLeftPercent="30%"/>
<com.example.afcosta.inesctec.pt.android.Helpers.OpenSansMedium
android:id="#+id/textView8"
android:text="Espécie"
android:textSize="14dp"
app:layout_widthPercent="25%"
app:layout_heightPercent="5%"
app:layout_marginTopPercent="85%"
app:layout_marginLeftPercent="5%"
/>
<com.example.afcosta.inesctec.pt.android.Helpers.OpenSansMedium
android:id="#+id/textView7"
app:layout_widthPercent="25%"
app:layout_heightPercent="5%"
app:layout_marginTopPercent="95%"
app:layout_marginLeftPercent="5%"
android:text="Género"
android:textSize="14dp" />
<com.example.afcosta.inesctec.pt.android.Helpers.OpenSansMedium
android:id="#+id/Family"
app:layout_widthPercent="25%"
app:layout_heightPercent="5%"
app:layout_marginTopPercent="105%"
app:layout_marginLeftPercent="5%"
android:text="Familia"
android:textSize="14dp" />
<com.example.afcosta.inesctec.pt.android.Helpers.OpenSansMedium
android:id="#+id/specieDescription"
android:textSize="14dp"
app:layout_widthPercent="90%"
android:layout_height="wrap_content"
app:layout_marginTopPercent="120%"
app:layout_marginLeftPercent="5%"/>
<com.example.afcosta.inesctec.pt.android.Helpers.OpenSansMedium
android:id="#+id/descricaoTit"
android:text="Descrição"
android:textSize="14dp"
app:layout_widthPercent="30%"
app:layout_heightPercent="5%"
app:layout_marginTopPercent="115%"
app:layout_marginLeftPercent="5%"/>
<ImageView
android:id="#+id/plantImage"
android:adjustViewBounds="true"
android:scaleType="fitXY"
app:layout_widthPercent="80%"
app:layout_heightPercent="50%"
app:layout_marginTopPercent="12%"
app:layout_marginLeftPercent="10%"
app:srcCompat="#drawable/color_cursor_white" />
<android.support.v7.widget.RecyclerView
android:id="#+id/gallery"
app:layout_widthPercent="100%"
app:layout_heightPercent="10%"
app:layout_marginTopPercent="62%"
app:layout_marginLeftPercent="0%" />
<RelativeLayout
app:layout_widthPercent="40%"
app:layout_heightPercent="5%"
app:layout_marginTopPercent="75%"
app:layout_marginLeftPercent="5%"
android:onClick="showMap">
<com.example.afcosta.inesctec.pt.android.Helpers.OpenSansMedium
android:id="#+id/googleMapsText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/imageView6"
android:layout_alignBottom="#+id/imageView6"
android:text="Ver no mapa" />
<ImageView
android:id="#+id/imageView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_facebook_placeholder_for_locate_places_on_maps"
android:tint="#F90101" />
</RelativeLayout>
</android.support.percent.PercentRelativeLayout>
</LinearLayout>
</ScrollView>
First for solving your problem with ScrollView you must know ScrollView works if you put a LinearLayout to be child of it and then cut all your Views inside this LinearLayout .
See this tree :
| ScrollView
|-- LinearLayout
|---- OtherViews you want to scroll
Its not important what you want to put Scrolling . you must follow this way.
EDIT :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
// everything you want to scroll
</LinearLayout>
</ScrollView>
</LinearLayout>

How to keep a View on top of my Fragments

Sounds like a question that was answered before but from my research I couldn't find a solution. My layout is roughly the following:
The main area is a container where I'll add/replace Fragments, and the bottom is where I place a bottom navigation menu. The pink View is a button that I need to place on top of my menu (and that's not working).
Every time I add a Fragment to the main view, my "Menu" text disappears, even though the TextView is added after the container View. Same with the pink Button, which is added after the bottom menu container (see my xml below).
How can I keep both "Menu" TextView and the pink Button always on top of my Fragments?
This is my xml:
<RelativeLayout 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:background="#eee"
tools:context="com.wecancer.wecancer.activities.Menu">
<FrameLayout
android:id="#+id/main_container_view"
android:layout_width="match_parent"
android:layout_height="520dp"
android:layout_marginBottom="0dp"
>
</FrameLayout>
<TextView
android:id="#+id/main_center_tv"
android:layout_centerVertical="true"
android:textSize="24sp"
android:layout_centerHorizontal="true"
android:text="#string/menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<FrameLayout
android:layout_alignParentBottom="true"
android:id="#+id/main_bottom_menu_container"
android:layout_width="match_parent"
android:background="#color/lightGray"
android:layout_height="40dp"
>
</FrameLayout>
<Button
android:elevation="1dp"
android:id="#+id/menu_plus_img"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:background="#color/colorAccent"
android:layout_width="70dp"
android:layout_marginBottom="0dp"
android:layout_height="70dp"
tools:targetApi="lollipop" />
</RelativeLayout>
Try This`
<FrameLayout
android:layout_alignParentBottom="true"
android:id="#+id/main_bottom_menu_container"
android:layout_width="match_parent"
android:background="#color/colorPrimary"
android:layout_height="40dp"
>
</FrameLayout>
<Button
android:elevation="1dp"
android:id="#+id/menu_plus_img"
android:background="#color/colorAccent"
android:layout_width="70dp"
android:layout_height="70dp"
tools:targetApi="lollipop"
android:layout_marginLeft="71dp"
android:layout_marginStart="71dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:id="#+id/main_center_tv"
android:textSize="24sp"
android:text="#string/menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:layout_alignBaseline="#+id/menu_plus_img"
android:layout_alignBottom="#+id/menu_plus_img"
android:layout_toRightOf="#+id/menu_plus_img"
android:layout_toEndOf="#+id/menu_plus_img" />
<FrameLayout
android:id="#+id/main_container_view"
android:layout_width="match_parent"
android:layout_height="520dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/menu_plus_img">
</FrameLayout>
`
You just have to change the order of the views in the layout while using a Framelayout
The complexity of your layout does not require a RelativeLayout so you just have to switch.
I don't really know why methods like bringToFront, bringChildToFront, or adding and removing View's children to change their indices didn't work. So I actually had to create a new layout structure.
Instead of:
RelativeLayout
...FrameLayout
...TextView
...FrameLayout
...Button
I did:
FrameLayout
...RelativeLayout
......FrameLayout
......FrameLayout
......TextView
...RelativeLayout
......Button
Whereas the second RelativeLayout has only a button and a transparent background. My full xml code is below as a reference.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/main_root_view"
android:layout_height="match_parent">
<RelativeLayout
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#eee"
tools:context="com.wecancer.wecancer.activities.Menu">
<FrameLayout
android:layout_alignParentBottom="true"
android:id="#+id/main_bottom_menu_container"
android:layout_width="match_parent"
android:background="#color/lightGray"
android:layout_height="wrap_content" />
<FrameLayout
android:id="#+id/main_container_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="0dp" />
<TextView
android:id="#+id/main_center_tv"
android:layout_centerVertical="true"
android:textSize="24sp"
android:layout_centerHorizontal="true"
android:text="#string/menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:onClick="menuPlusBt"
android:elevation="5dp"
android:id="#+id/menu_plus_img"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:background="#drawable/green_circle"
android:layout_width="70dp"
android:layout_marginBottom="0dp"
android:layout_height="70dp"
tools:targetApi="lollipop" />
</RelativeLayout>
</FrameLayout>

Categories

Resources