解决fragment replace 重叠现象
生活随笔
收集整理的這篇文章主要介紹了
解决fragment replace 重叠现象
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
同一個Activity通過frameLayout的方式放置一個fragment,通過其中一個fragment來啟動另外一個fragment
出現了如下的錯誤,兩個fragment重疊到一起了,導致了控件的重疊
布局如下:
主布局:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools" android:id="@+id/fragment"android:name="com.example.lyh.myapplication.MainActivityFragment"tools:layout="@layout/fragment_main" android:layout_width="match_parent"android:layout_height="match_parent"/> 第一個fragment布局: <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"android:paddingRight="@dimen/activity_horizontal_margin"android:paddingTop="@dimen/activity_vertical_margin"android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivityFragment"android:orientation="vertical"android:layout_margin="0dp"><LinearLayoutandroid:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="vertical"><TextView android:text="@string/hello_world" android:layout_width="wrap_content"android:layout_height="wrap_content"android:id="@+id/textView" /><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:id="@+id/but1"android:text="啟動另一個fragment" /></LinearLayout> </FrameLayout> 第二個fragm布局: <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical" android:layout_width="match_parent"android:layout_height="match_parent"><LinearLayoutandroid:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="vertical"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:id="@+id/te2"android:text="這是另一個fragment"/><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:id="@+id/but2"android:text="返回"/></LinearLayout></FrameLayout>解決方法,在第二個fragment的FrameLayout里給個加個白色的背景: android:background="#ffffff" 為了不讓點擊第二個fragment的某些地方,觸發(fā)第一個fragment里的控件事件,需要在第二個fragment的FrameLayout里加上: android:clickable="true"問題到此得到解決總結
以上是生活随笔為你收集整理的解决fragment replace 重叠现象的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Django学习(一)
- 下一篇: 解决php写入mysql乱码问题汇总