Java 浮动提交按钮

Java 浮动提交按钮,java,android,Java,Android,“活动”布局中的“提交”按钮会浮动到手机屏幕的左上角,即使在添加了片段后,也会使片段的某些内容变得模糊。调用以下代码时,是否不应将其按下: currentFragment=MyFragment.newInstance(); getSupportFragmentManager().beginTransaction() .replace(R.id.my_fragment,currentFragment).commit() 活动布局: <?xml version="1.0" encoding="

“活动”布局中的“提交”按钮会浮动到手机屏幕的左上角,即使在添加了片段后,也会使片段的某些内容变得模糊。调用以下代码时,是否不应将其按下:

currentFragment=MyFragment.newInstance(); getSupportFragmentManager().beginTransaction() .replace(R.id.my_fragment,currentFragment).commit()

活动布局:

<?xml version="1.0" encoding="UTF-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
             xmlns:tools="http://schemas.android.com/tools" android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <fragment android:name="com.mycompany.myapp.MyFragment"
              android:id="@+id/my_fragment"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              tools:layout="@layout/my_fragment_layout"/>
    <Button
            android:id="@+id/submit_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/submit_button_text"
            />
</FrameLayout>

片段布局(my_Fragment_layout.xml):



关于片段和布局,我缺少什么?

根据您的要求,您的
活动
父布局应该是
线性布局
相对布局
而不是
框架布局
。还为
片段
布局设置布局权重,使其占据
按钮所使用的剩余空间

像这样更改活动布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

 <fragment 
    android:id="@+id/my_fragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:layout="@layout/my_fragment_layout"
    android:layout_weight="100"/>
 <Button
    android:id="@+id/submit_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="submit_button_text"/>
</LinearLayout>
希望这有助于解决您的问题

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

 <fragment 
    android:id="@+id/my_fragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:layout="@layout/my_fragment_layout"
    android:layout_weight="100"/>
 <Button
    android:id="@+id/submit_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="submit_button_text"/>
</LinearLayout>
 <FrameLayout 
    android:id="@+id/my_fragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="100"/>