使用fragmentManeger添加一个fragment时,使用linerlayout布局的子fragment无法充满父容器.

WangW_No.4 2015-12-04 09:58:58
这个问题是突然出现了,之前一直没有.
下面贴出添加fragment的代码.
FragmentActivity activity = getActivity();
if (activity != null) {
FragmentManager fragmentManager = activity.getSupportFragmentManager();
FragmentTransaction transaction = fragmentManager.beginTransaction();
fragment.setArguments(args);
if (aminEnable) {
transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
}
transaction.add(layoutId, fragment, tag);
transaction.addToBackStack(stackName);
transaction.commitAllowingStateLoss();
fragmentManager.executePendingTransactions();
}

如果把linerlayout换成Relatevlayout就不会出现无法充满全屏的问题.linerlayout开头如下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_main"
android:clickable="true"
android:orientation="vertical" >
...全文
461 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
灰狼Allan 2017-08-15
  • 打赏
  • 举报
回复
View mView = inflater.inflate(R.id.content, container, false);就可以了
柒加伊 2015-12-04
  • 打赏
  • 举报
回复
fragment的布局有没有 ?
shililang 2015-12-04
  • 打赏
  • 举报
回复
多套一层布局叠在里面
WangW_No.4 2015-12-04
  • 打赏
  • 举报
回复
<?xml version="1.0" encoding="utf-8"?> <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="fill_parent" android:background="#f7f7f7" android:clickable="true" android:orientation="vertical" > <org.aurora.micorprovider.views.actionbar.NormalActionBar xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/action_bar" android:layout_width="match_parent" android:layout_height="wrap_content" app:actionBarMode="none" app:actionBarTitle="@string/account_login" /> <RelativeLayout android:id="@+id/view_country" android:layout_width="match_parent" android:layout_height="@dimen/dp100" android:background="@drawable/white" android:orientation="horizontal" android:paddingLeft="@dimen/dp30" android:paddingRight="@dimen/dp30" > <TextView android:id="@+id/textview_country" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_toLeftOf="@+id/enter" android:text="中国" android:textColor="@color/font_gray_light" android:textSize="@dimen/sp18" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_centerVertical="true" android:text="@string/country" android:textColor="@color/font_gray_light" android:textSize="@dimen/sp18" /> <ImageView android:id="@+id/enter" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:background="@drawable/btn_enter_bg" /> </RelativeLayout> <View android:layout_width="match_parent" android:layout_height="1px" android:background="@drawable/line_dark" /> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/white" android:paddingLeft="@dimen/dp30" android:paddingRight="@dimen/dp30" > <EditText android:id="@+id/editText_phone" style="@style/Edit_normal" android:layout_width="match_parent" android:layout_height="@dimen/dp100" android:layout_centerVertical="true" android:layout_marginLeft="@dimen/dp10" android:layout_toRightOf="@+id/country_code" android:background="@drawable/edit_bg_white" android:hint="@string/account_login_account_hint" android:inputType="number" android:maxLength="32" android:singleLine="true" android:textSize="@dimen/sp18" > </EditText> <TextView android:id="@+id/country_code" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_centerVertical="true" android:text="+86" android:textColor="@color/font_gray_light" android:textSize="@dimen/sp18" /> </RelativeLayout> <View android:layout_width="match_parent" android:layout_height="1px" android:background="@drawable/line_dark" /> <View android:layout_width="match_parent" android:layout_height="1px" android:layout_marginTop="@dimen/dp20" android:background="@drawable/line_dark" /> <EditText android:id="@+id/editText_password" style="@style/account_edit" android:hint="请输入密码" android:maxLength="20" android:password="true" android:singleLine="true" > </EditText> <View android:layout_width="match_parent" android:layout_height="1px" android:background="@drawable/line_dark" /> <LinearLayout android:layout_width="match_parent" android:layout_height="@dimen/dp80" android:gravity="right" android:orientation="horizontal" > <TextView android:id="@+id/textView_find_pwd" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_marginRight="@dimen/dp40" android:gravity="center" android:text="忘记密码" android:textColor="@color/font_yellow_drak" android:textSize="@dimen/sp16" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="50dp" > <Button android:id="@+id/button_login" style="@style/Button_normal" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="@dimen/dp40" android:layout_marginRight="@dimen/dp40" android:text="@string/account_login" /> </LinearLayout> </LinearLayout>

80,350

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧