我在一个大的EditText上有一个FloatingActionButton。当我启动应用程序并尝试点击FloatingActionButton时,键盘会翻转,因为它需要点击EditText。
我需要在代码中更改什么,以便FloatingActionButton在"以上" EditText?
我发现我需要最后添加FloatingActionButton,我已经做过,这样它就在顶部,但它没有用。我也实现了一个onClickListener,我想这不是问题。
这是我布局的屏幕截图: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();
}
}
});
答案 0 :(得分:1)
将您的FloatingActionButton置于框架布局中,并根据要显示的位置设置其重力和填充。
<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>