So I have an activity with 2 empty ListView's and 3 Buttons. The "Hinzufügen" Button (seen in Screenshot) should load a Fragment into a Framelayout (used as Container) to lay over all components (ListView's and Buttons) from the activity. But I don't know why it lays behind all of them (can't click the Button of the Fragment because it's behind an empty ListView).
Screenshot without Fragment started:
https://abload.de/img/dqwdwqemuhi.jpeg
Screenshot with Fragment started:
https://abload.de/img/fewqfewp7u0b.jpeg
If I get the container with
View view = findViewById(R.id.container);
and then use
view.bringtToFront();
the Buttons from the activity are still shown but the ListView's are in the background (can click the button from the fragment now).
How do I get the buttons from the activity in the background so that the fragment lays over the whole activity and its components?
Activity XML:
<?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"
tools:context="superhelden.com.superheldenuebersichtsapp.Activities.DeckOverview">
<FrameLayout
android:id="#+id/addCardsContainer"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
</FrameLayout>
<android.support.constraint.Guideline
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/guideline3"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.65"
tools:layout_editor_absoluteY="332dp"
tools:layout_editor_absoluteX="0dp" />
<android.support.constraint.Guideline
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/guideline4"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.4"
tools:layout_editor_absoluteY="0dp"
tools:layout_editor_absoluteX="154dp" />
<Button
android:id="#+id/addCards"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:text="#string/addCards"
app:layout_constraintRight_toLeftOf="#+id/guideline4"
app:layout_constraintTop_toTopOf="#+id/guideline3"
android:layout_marginTop="8dp"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent" />
<Button
android:id="#+id/removeCards"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:text="#string/removeCards"
app:layout_constraintBottom_toTopOf="#+id/guideline5"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="#+id/guideline4"
app:layout_constraintTop_toBottomOf="#+id/addCards"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp" />
<Button
android:id="#+id/endGame"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:text="#string/endGame"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="#+id/guideline4"
app:layout_constraintTop_toTopOf="#+id/guideline5"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp" />
<android.support.constraint.Guideline
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/guideline5"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.88"
tools:layout_editor_absoluteY="450dp"
tools:layout_editor_absoluteX="0dp" />
<ListView
android:id="#+id/amountOfTypesList"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
app:layout_constraintLeft_toLeftOf="#+id/guideline4"
app:layout_constraintTop_toTopOf="#+id/guideline3"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="8dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp" />
<ListView
android:id="#+id/deckList"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:divider="#000"
android:dividerHeight="0.5dp"
android:scrollbars="horizontal"
app:layout_constraintBottom_toTopOf="#+id/guideline3"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
</android.support.constraint.ConstraintLayout>
Activity Java:
public class DeckOverview extends AppCompatActivity {
FragmentManager fragmentManager;
FragmentTransaction fragmentTransaction;
Button addCardsButton;
Button removeCardsButton;
Button endGameButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_deck_overview);
addCardsButton = (Button) findViewById(R.id.addCards);
addCardsButton.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v) {
fragmentManager = getFragmentManager();
fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.addCardsContainer, new addCards());
fragmentTransaction.addToBackStack("addCards");
fragmentTransaction.commit();
}
});
removeCardsButton = (Button) findViewById(R.id.removeCards);
removeCardsButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//TODO: Karten aus Tabelle in der DB entfernen
}
});
endGameButton = (Button) findViewById(R.id.endGame);
endGameButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), EndScreen.class);
startActivity(intent);
finish();
}
});
}
}
Fragment XML:
<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:background="#color/colorAccent"
tools:context="superhelden.com.superheldenuebersichtsapp.Fragments.addCards">
<ListView
android:id="#+id/allCardsList"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="#+id/guideline7"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="#+id/guideline6"
app:layout_constraintTop_toTopOf="#+id/guideline10"
style="#style/Margin_And_Divider_Style"/>
<ListView
android:id="#+id/selectedCardsList"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="#+id/guideline7"
app:layout_constraintLeft_toLeftOf="#+id/guideline6"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="#+id/guideline10"
style="#style/Margin_And_Divider_Style"/>
<Button
android:id="#+id/doneButtonAddCards"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:text="#string/done"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="#+id/guideline7"
app:layout_constraintVertical_bias="0.571" />
<android.support.constraint.Guideline
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/guideline6"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.5"
tools:layout_editor_absoluteY="0dp"
tools:layout_editor_absoluteX="180dp" />
<android.support.constraint.Guideline
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/guideline7"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.86"
tools:layout_editor_absoluteY="439dp"
tools:layout_editor_absoluteX="0dp" />
<android.support.constraint.Guideline
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/guideline10"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.1"
tools:layout_editor_absoluteY="51dp"
tools:layout_editor_absoluteX="0dp" />
<SearchView
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:id="#+id/searchView"
app:layout_constraintBottom_toTopOf="#+id/guideline10"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" />
</android.support.constraint.ConstraintLayout>
Fragment Java:
List<Card> allCardsList;
ListView allCardsListView;
View addCards;
public addCards() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
allCardsList = DbClass.getInstance(getActivity()).getAllCards();
allCardsListView = (ListView) getActivity().findViewById(R.id.allCardsList);
Toast.makeText(getActivity(), allCardsList.get(0).getName(), Toast.LENGTH_SHORT).show();
addCards = inflater.inflate(R.layout.fragment_add_cards, container, false);
return addCards;
}
move addCardsContainer to the bottom of your Activity XML (last child of ConstraintLayout). Drawing is always in order of positioning in inflated layout file. bringToFront is not for this case
...
<FrameLayout
android:id="#+id/addCardsContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</android.support.constraint.ConstraintLayout>
because of margin you may still see a fragment of your buttons in layer below. you can replace layout_margin with padding and set some background for cover
android:padding="20dp"
android:background="#000000"
Related
I'm trying to open a Fragment from a Activity by using the fragmentManager.replace() function, but it doesn't do anything and the Logcat tells me nothing either. I have tried using both FragmentContainerView and FrameLayout inside my activity_main.xml, and even using the activity's ConstraintLayout ID to host the Fragment, but to no avail.
Here are the codes for my Activity that should open the fragment, and the fragment code itself:
OsActivity.java
import androidx.fragment.app.FragmentTransaction;
import android.os.Bundle;
import android.view.View;
import com.leonardomaito.autocommobile.fragments.NewOsFragment;
import autocommobile.R;
public class OsActivity extends AppCompatActivity {
NewOsFragment newOsFragment = new NewOsFragment();
private View v;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_os);
}
public void createNewOs(View view) {
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.setReorderingAllowed(true);
fragmentTransaction.replace(R.id.osFragmentContainer, newOsFragment);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
}
NewOsFragment.java
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import autocommobile.R;
public class NewOsFragment extends Fragment {
private Button btOsNext;
private Button btOsCancel;
private Fragment nextOs = new Fragment();
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_new_os, container, false);
btOsNext = view.findViewById(R.id.btNextOs);
btOsCancel = view.findViewById(R.id.btCancelNewOs);
return view;
}
public void nextOsStep(View view) {
FragmentTransaction fragmentManager = getActivity()
.getSupportFragmentManager()
.beginTransaction()
.replace(R.id.fragment_new_os, nextOs);
}
}
ActivityOs.xml
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/activity_os"
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:layout_marginBottom="0dp"
android:background="#color/white"
tools:context="com.leonardomaito.autocommobile.activities.OsActivity">
<androidx.fragment.app.FragmentContainerView
android:id="#+id/osFragmentContainer"
android:name="com.leonardomaito.autocommobile.fragments.NewOsFragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:layout="#layout/fragment_new_os">
</androidx.fragment.app.FragmentContainerView>
<include
android:id="#+id/include"
layout="#layout/layout_header_search" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/glRecyclerLimit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_begin="124dp" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/recyclerViewOs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="650dp"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/glRecyclerLimit"
app:layout_constraintVertical_bias="0.0"
tools:listitem="#layout/layout_os_item" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="#+id/btNewOs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="Inserir OS"
android:onClick="createNewOs"
android:src="#drawable/custom_plus_icon"
app:backgroundTint="#color/autocom_blue"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.98"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="#+id/glRecyclerLimit"
app:layout_constraintVertical_bias="0.988"
app:rippleColor="#color/autocom_blue" />
</androidx.constraintlayout.widget.ConstraintLayout>
fragment_new_os.xml
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/fragment_new_os"
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.leonardomaito.autocommobile.fragments.NewOsFragment">
<TextView
android:id="#+id/tvServiceOrder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:text="Ordem de Serviço"
android:textColor="#color/autocom_blue"
android:textSize="30sp"
app:layout_constraintBottom_toTopOf="#+id/viewHorizontalBar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0" />
<View
android:id="#+id/viewHorizontalBar"
android:layout_width="match_parent"
android:layout_height="3dp"
android:layout_marginTop="32dp"
android:background="#color/autocom_blue"
app:layout_constraintBottom_toTopOf="#+id/glViewBottom"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0" />
<androidx.constraintlayout.widget.Guideline
android:id="#+id/glViewBottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_begin="57dp" />
<TextView
android:id="#+id/tvCliente"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="136dp"
android:text="Cliente"
android:textColor="#color/autocom_blue"
android:textSize="30sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.084"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/viewHorizontalBar" />
<EditText
android:id="#+id/etClientInput"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:background="#drawable/custom_border"
android:drawableStart="#drawable/custom_search_icon"
android:ems="17"
android:importantForAutofill="no"
android:inputType="text"
android:minHeight="48dp"
android:textColor="#color/autocom_blue"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.49"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/tvCliente" />
<TextView
android:id="#+id/tvAddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="48dp"
android:text="Endereço"
android:textColor="#color/autocom_blue"
android:textSize="30sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.094"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/etClientInput" />
<EditText
android:id="#+id/etAddressInput"
android:enabled="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:background="#drawable/custom_border"
android:ems="17"
android:inputType="text"
android:minHeight="48dp"
android:textColor="#color/autocom_blue"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.49"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/tvAddress"
android:importantForAutofill="no" />
<TextView
android:id="#+id/tvTelephone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="52dp"
android:text="Telefone"
android:textColor="#color/autocom_blue"
android:textSize="30sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.091"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/etAddressInput" />
<EditText
android:id="#+id/etTelephoneInput"
android:enabled="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:background="#drawable/custom_border"
android:ems="17"
android:inputType="text"
android:minHeight="48dp"
android:textColor="#color/autocom_blue"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.49"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/tvTelephone"
android:importantForAutofill="no" />
<android.widget.Button
android:id="#+id/btNextOs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="64dp"
android:background="#drawable/custom_button"
android:minWidth="125dp"
android:onClick="nextOsStep"
android:text="Avançar"
android:textColor="#color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/etTelephoneInput"
app:layout_constraintVertical_bias="0.155" />
</androidx.constraintlayout.widget.ConstraintLayout>
Shouldn't the replace function be opening my fragment on top of my activity? Is there something I'm doing wrong? The majority of other posts adressing this situation seemed to use .add instead of .replace, and were fixed by doing so.
Trying to make two login, one for admin, one for user. They share the same layout, but admin has additional TextFields and Buttons to add data to the menu. So when logging in with user credentials, the TextFields and Buttons will be setVisibility(View.GONE), but it's not working at all, in fact it's showing up like setVisibility(View.GONE) was added at all. Any advice would be appreciated.
loginpage.java
DatabaseHelper myDB;
EditText LoginEMail;
EditText LoginPassword;
Button LoginBtn;
LinearLayout linearLayout;
View add_image;
View add_name;
View add_desc;
View add_data;
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.loginpage);
LoginEMail = findViewById(R.id.LoginEMail);
LoginPassword = findViewById(R.id.LoginPassword);
LoginBtn = findViewById(R.id.LoginBtn);
myDB = new DatabaseHelper(this);
linearLayout = findViewById(R.id.linearLayout);
linearLayout = new LinearLayout(this);
add_image = new View(this);
add_name = new View(this);
add_desc = new View(this);
add_data = new View(this);
}
public void Login(View view) {
Intent intent = new Intent(loginpage.this, MenuSelection.class);
if (LoginEMail.getText().toString().equals("admin") && (LoginPassword.getText().toString().equals("admin"))) {
startActivity(intent);
linearLayout.setVisibility(View.VISIBLE);
}
else if(LoginEMail.getText().toString().equals("user") && (LoginPassword.getText().toString().equals("user"))) {
startActivity(intent);
linearLayout.setVisibility(View.GONE);
add_image.setVisibility(View.GONE);
add_name.setVisibility(View.GONE);
add_desc.setVisibility(View.GONE);
add_data.setVisibility(View.GONE);
}
else
Toast.makeText(loginpage.this, "Incorrect E-mail or Password.", Toast.LENGTH_SHORT).show();
}
loginpage.xml
<?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="match_parent">
<EditText
android:id="#+id/LoginEMail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="E-Mail"
android:inputType="textEmailAddress"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.504"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.204" />
<EditText
android:id="#+id/LoginPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Password"
android:inputType="textPassword"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.495"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.338" />
<Button
android:id="#+id/LoginBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Log In"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.502"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.602"
android:onClick="Login"/>
</androidx.constraintlayout.widget.ConstraintLayout>
menu_selection.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="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical">
<ListView
android:id="#+id/menu_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0">
<ImageButton
android:id="#+id/add_image"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="#color/black" />
<EditText
android:id="#+id/add_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Name" />
<EditText
android:id="#+id/add_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Description" />
<Button
android:id="#+id/add_data"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Instead of add_image = new View(this); you need to associate the variable add_image to the view in your XML layout using the findViewById(R.id.add_image) method. Similarly for the other 3 views that you have initialized this way.
You also need to delete the line linearLayout = new LinearLayout(this);. The previous line setting this variable is correct.
I have two EditText in MyActivity. Here I have provided UI XML.
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="#+id/button_insta"
android:layout_width="135dp"
android:layout_height="0dp"
android:layout_marginBottom="33dp"
android:text="Download"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<EditText
android:id="#+id/editUrli"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginTop="64dp"
android:layout_marginBottom="18dp"
android:ems="10"
android:inputType="textPersonName"
android:text=""
android:textColor="#0C0C0C"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
<TextView
android:id="#+id/textView2"
android:layout_width="177dp"
android:layout_height="39dp"
android:layout_marginEnd="81dp"
android:layout_marginRight="81dp"
android:text="Paste Instagram video link to download "
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="#+id/imageView3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/imageView3"
app:layout_constraintTop_toTopOf="#+id/imageView3" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="78dp"
android:layout_height="43dp"
android:layout_marginStart="41dp"
android:layout_marginLeft="41dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="18dp"
android:layout_marginRight="18dp"
android:src="#drawable/insta"
app:layout_constraintEnd_toStartOf="#+id/textView2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
<com.google.android.material.card.MaterialCardView
android:id="#+id/card"
android:layout_width="0dp"
android:layout_height="200dp"
android:layout_margin="8dp"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="MissingConstraints">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="#+id/editUrl"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginTop="64dp"
android:layout_marginBottom="18dp"
android:ems="10"
android:inputType="textPersonName"
android:text=""
android:textColor="#0C0C0C"
app:layout_constraintBottom_toTopOf="#+id/button_download"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/button_download"
android:layout_width="135dp"
android:layout_height="0dp"
android:layout_marginBottom="33dp"
android:text="Download"
android:onClick="onClick"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<ImageView
android:id="#+id/fblogo"
android:layout_width="95dp"
android:layout_height="39dp"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="13dp"
android:layout_marginEnd="18dp"
android:layout_marginRight="18dp"
android:layout_marginBottom="13dp"
android:contentDescription="TODO"
android:src="#drawable/fb"
app:layout_constraintBottom_toTopOf="#+id/editUrl"
app:layout_constraintEnd_toStartOf="#+id/textView"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
<TextView
android:id="#+id/textView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="75dp"
android:layout_marginRight="75dp"
android:layout_marginBottom="84dp"
android:text="Paste FB video link to download"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="#+id/button_download"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#+id/fblogo"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
In my Activity java code has this button click code
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_download);
inputURl = findViewById(R.id.editUrl);
editUrlinsta = findViewById(R.id.editUrli);
BtnDownload = (Button) findViewById(R.id.button_download);
downloadinsta = (Button) findViewById(R.id.button_insta);
BtnDownload.setOnClickListener(this);
downloadinsta.setOnClickListener(this);
}
#Override
public void onClick(View v) {
switch (v.getId()){
case R.id.button_download:
try{
final FacebookDownloader downloaders = new FacebookDownloader(Download.this,inputURl.getText().toString());
downloaders.DownloadVideo();
inputURl.getText().clear();
} catch(Exception e) {}
break;
case R.id.button_insta:
final InstaDownloader downloaderInsta = new InstaDownloader(Download.this,editUrlinsta.getText().toString());
downloaderInsta.DownloadVideo();
editUrlinsta.getText().clear();
break;
default:
break;
}
}
The problem is The first button which I have named button_download is working as expected. But the second button button_insta not working as expected. what I want to do, is When one of the buttons clicks, getting data from EditText. The button_download works fine. the button_insta is not working fine.
I couldn't get value from editUrli when the button click. But same code works for button_download and editUrl
Try to separate those button click function like so :
BtnDownload.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
try{
final FacebookDownloader downloaders = new FacebookDownloader(Download.this,inputURl.getText().toString());
downloaders.DownloadVideo();
inputURl.getText().clear();
} catch(Exception e) {}
}
});
downloadinsta.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final InstaDownloader downloaderInsta = new InstaDownloader(Download.this,editUrlinsta.getText().toString());
downloaderInsta.DownloadVideo();
editUrlinsta.getText().clear();
}
});
I find that there is a quick way to create animation with ConstraintSet for ConstrainLayout Activity. Faster than use TransitionManager for RelativeLayout
ConstraintSet use two xml file for an Activity. One for the first position and next one for the destination.
I want to create something like this:
https://media.giphy.com/media/2UwXdWEoLWe9iQMFIY/giphy.gif
But there is no clearly instruction show how to use it in Java. Anyone had done this can show me the source code or link to some post like that.
Thanks for reading the post.
This is possible with ConstraintSet. They key is two have two layouts one layout has ui elements of the screen and the other has elements on the screen. Now you can use TransitionManager with interpolator and duration of your choice and animate the layout changes.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
android:id="#+id/constraint"
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="#181818"
tools:context=".MainActivity">
<ImageView
android:id="#+id/backgroundImage"
android:layout_width="0dp"
android:layout_height="0dp"
android:src="#drawable/mugello"
android:scaleType="centerCrop"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="JUNE 3, 2018"
app:layout_constraintRight_toRightOf="#+id/title"
app:layout_constraintBottom_toBottomOf="#+id/title"
android:textSize="12sp"
android:background="#d3d3d3"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:paddingTop="3dp"
android:paddingBottom="3dp"/>
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="48dp"
android:background="#F44336"
android:paddingBottom="8dp"
android:paddingEnd="24dp"
android:paddingStart="24dp"
android:paddingTop="8dp"
android:text="Mugello Circuit"
android:textColor="#FFFF"
android:textSize="45sp"
app:layout_constraintRight_toLeftOf="#+id/backgroundImage"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="#+id/fadeBackgroudView"
android:layout_width="wrap_content"
android:layout_height="90dp"
android:foreground="#drawable/gradient_variant"
app:layout_constraintBottom_toTopOf="#+id/description" />
<TextView
android:id="#+id/tap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="12dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:text="Tap for info"
android:textSize="15sp"
android:textColor="#ffffff"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="#+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="The Mugello is a historic region and valley in northern Tuscany, in Italy. It is located to the north of the city of Florence and consists of the northernmost portion of the Metropolitan City of Florence. It is connected to the separate Santerno river valley by the Futa Pass."
android:textSize="22sp"
android:textColor="#FFFF"
android:background="#181818"
android:gravity="center"
android:paddingStart="8dp"
android:paddingEnd="8dp"
android:paddingBottom="8dp"
app:layout_constraintTop_toBottomOf="#+id/backgroundImage"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"/>
</android.support.constraint.ConstraintLayout>
activity_main_detail.xml
<?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"
tools:context=".MainActivity">
<ImageView
android:id="#+id/backgroundImage"
android:layout_width="0dp"
android:layout_height="0dp"
android:scaleType="centerCrop"
android:src="#drawable/mugello"
app:layout_constraintBottom_toTopOf="#+id/description"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="48dp"
android:background="#F44336"
android:paddingBottom="8dp"
android:paddingEnd="24dp"
android:paddingStart="24dp"
android:paddingTop="8dp"
android:text="Mugello Circuit"
android:textColor="#FFFF"
android:textSize="45sp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="JUNE 3, 2018"
app:layout_constraintRight_toRightOf="#+id/title"
app:layout_constraintTop_toBottomOf="#+id/title"
android:textSize="12sp"
android:background="#d3d3d3"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:paddingTop="3dp"
android:paddingBottom="3dp"/>
<View
android:id="#+id/fadeBackgroudView"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:foreground="#drawable/gradient"
app:layout_constraintBottom_toTopOf="#+id/description" />
<TextView
android:id="#+id/tap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:text="Tap for info"
android:textSize="15sp"
android:textColor="#ffffff"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="#+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="The Mugello is a historic region and valley in northern Tuscany, in Italy. It is located to the north of the city of Florence and consists of the northernmost portion of the Metropolitan City of Florence. It is connected to the separate Santerno river valley by the Futa Pass."
android:textSize="22sp"
android:textColor="#FFFF"
android:gravity="center"
android:background="#181818"
android:paddingStart="8dp"
android:paddingEnd="8dp"
android:paddingBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"/>
</android.support.constraint.ConstraintLayout>
MainActivity.java
public class MainActivity extends AppCompatActivity {
private boolean show = false;
private ImageView backgroundImage;
private ConstraintLayout constraint;
private ConstraintSet constraintSet = new ConstraintSet();
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
constraint = findViewById(R.id.constraint);
backgroundImage = findViewById(R.id.backgroundImage);
backgroundImage.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if(show)
hideComponents(); // if the animation is shown, we hide back the views
else
showComponents() ;// if the animation is NOT shown, we animate the views
}
});
}
private void showComponents(){
show = true;
constraintSet.clone(this, R.layout.activity_main_detail);
Transition transition = new ChangeBounds();
transition.setInterpolator(new AnticipateOvershootInterpolator(1.0f));
transition.setDuration(1000);
TransitionManager.beginDelayedTransition(constraint, transition);
constraintSet.applyTo(constraint);
}
private void hideComponents(){
show = false;
constraintSet.clone(this, R.layout.activity_main);
Transition transition = new ChangeBounds();
transition.setInterpolator(new AnticipateOvershootInterpolator(1.0f));
transition.setDuration(1000);
TransitionManager.beginDelayedTransition(constraint, transition);
constraintSet.applyTo(constraint);
}
}
Here's a slide share on ConstraintLayout https://speakerdeck.com/camaelon/advanced-animations-and-constraintlayout
I have a FloatingActionButton over a big EditText. When I launch the app and try to tap on the FloatingActionButton the keyboard flips up because it takes the tap of the EditText.
What do I need to change in my code such that the FloatingActionButton is "above" the EditText?
I found that I need to add the FloatingActionButton last, what I already did, such that it is on top, but it didn't work. I also have implemented an onClickListener, which I suppose is not the problem.
Here a screenshot of my layout: Layout Screenshot
<?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="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#drawable/listviewbackground"
android:backgroundTint="#80FFFFFF"
android:backgroundTintMode="src_over"
>
<EditText
android:id="#+id/itemTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:hint="What do you need to do?"
android:textAlignment="center"
android:textAppearance="?attr/textAppearanceListItem"
android:textSize="30dp"
android:background="#android:color/transparent"/>
<android.support.constraint.ConstraintLayout
android:id="#+id/constraintLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/itemTitle"
android:paddingTop="50dp"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="2"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true">
<TextView
android:id="#+id/DueDate"
android:layout_width="0dp"
android:layout_height="39dp"
android:layout_marginEnd="64dp"
android:layout_marginStart="40dp"
android:layout_weight="1"
android:text="Due Date"
android:textAlignment="textStart"
android:textSize="24dp"
app:layout_constraintEnd_toStartOf="#+id/Date"
app:layout_constraintStart_toStartOf="parent"
tools:layout_editor_absoluteY="0dp" />
<TextView
android:id="#+id/Date"
android:layout_width="110dp"
android:layout_height="33dp"
android:layout_marginEnd="32dp"
android:layout_weight="1.2"
android:clickable="true"
android:focusable="false"
android:onClick="openCalendarView"
android:textAlignment="center"
android:textSize="18dp"
app:layout_constraintEnd_toEndOf="parent"
tools:layout_editor_absoluteY="0dp" />
<TextView
android:id="#+id/Important"
android:layout_width="149dp"
android:layout_height="39dp"
android:layout_marginBottom="8dp"
android:layout_marginStart="40dp"
android:layout_marginTop="8dp"
android:text="Is important?"
android:textAlignment="textStart"
android:textSize="24dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/DueDate"
app:layout_constraintVertical_bias="0.0" />
<Switch
android:id="#+id/switch1"
android:layout_width="51dp"
android:layout_height="40dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_toRightOf="#id/Important"
android:gravity="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.59"
app:layout_constraintStart_toEndOf="#+id/Important"
app:layout_constraintTop_toBottomOf="#+id/Date"></Switch>
</android.support.constraint.ConstraintLayout>
<EditText
android:id="#+id/Description"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:layout_below="#id/constraintLayout1"
android:background="#android:color/transparent"
android:hint="Put in your description"
android:inputType="textPersonName"
android:nextFocusLeft="#id/Description"
android:nextFocusUp="#id/Description"
android:paddingTop="20dp"
android:textAlignment="center"
android:textSize="18dp" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/floatingButtonDone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:paddingRight="5dp"
android:paddingLeft="5dp"
android:layout_gravity="bottom|end"
android:layout_margin="#dimen/fab_margin"
app:srcCompat="#drawable/check"
android:backgroundTint="#color/Green"
android:layout_alignBottom="#id/Description"
android:layout_alignParentRight="true"
android:focusable="true"
/>
</RelativeLayout>
Here my onClickListener
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_itemdetail, container, false);
//Getting Data and Creation of ToDoItem Object
FloatingActionButton floatingbutton = view.findViewById(R.id.floatingButtonDone);
floatingbutton.bringToFront();
floatingbutton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//Getting Data
try {
//Do something
} catch (Exception e) {
Snackbar.make(view, "You need to set a Title", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
}
});
Put your FloatingActionButton inside a frame layout and set its gravity and padding accordingly where you want to show it.
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
<android.support.design.widget.FloatingActionButton
android:id="#+id/floatingButtonDone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="#color/Green"
android:contentDescription="#null"
android:gravity="bottom|end"
android:padding="3dp"
android:src="#drawable/check" />
</FrameLayout>