【发布时间】:2014-04-18 07:03:51
【问题描述】:
即使在添加了片段后,活动布局中的提交按钮也会浮动到手机屏幕的左上角,从而导致它遮挡了片段的某些内容。调用以下代码时是否应该不下推:
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):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/question_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/text"/>
<RadioGroup android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radio_buttons"></RadioGroup>
</LinearLayout>
我在这里缺少关于片段和布局的什么?
【问题讨论】: