weixin_51755348 2022-03-08 16:46 采纳率: 25%
浏览 61

我的fragment把activity遮住了

当我点击第一个text按钮时,跳出来的fragment会把我先前的东西挡住

img

img


package com.example.h.addressbook;

import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        TextView textView= (TextView) findViewById(R.id.text1);
        textView.setOnClickListener(l);

    }
    View.OnClickListener l=new View.OnClickListener() {
        @Override
        public void onClick(View v) {
           FragmentManager fm = getFragmentManager();
            switch (v.getId()){
                case R.id.text1:
                    FragmentTransaction ft= fm.beginTransaction();
                    ft.replace(R.id.fragment,new AddressFragment()).commit();
                    break;
                default:break;
            }
        }
    };
}


``````xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.h.addressbook.MainActivity">

   <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/fragment">
    </FrameLayout>

   <ScrollView
       android:layout_width="match_parent"
       android:layout_height="match_parent">
       <LinearLayout
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:orientation="vertical">
       <TextView
           android:id="@+id/text1"
           android:layout_marginTop="10dp"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:text="刘亦菲"
           android:textSize="25dp"/>
       <TextView
           android:layout_marginTop="10dp"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:text="刘亦菲"
           android:textSize="25dp"/>
       <TextView
           android:layout_marginTop="10dp"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:text="刘亦菲"
           android:textSize="25dp"/>
       <TextView
           android:layout_marginTop="10dp"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:text="刘亦菲"
           android:textSize="25dp"/>
       <TextView
           android:layout_marginTop="10dp"
           android:layout_width="match_parent"
           android:layout_height="wrap_content"
           android:text="刘亦菲"
           android:textSize="25dp"/>
           <TextView
               android:layout_marginTop="10dp"
               android:layout_width="match_parent"
               android:layout_height="wrap_content"
               android:text="刘亦菲"
               android:textSize="25dp"/>
           <TextView
               android:layout_marginTop="10dp"
               android:layout_width="match_parent"
               android:layout_height="wrap_content"
               android:text="刘亦菲"
               android:textSize="25dp"/>
           <TextView
               android:layout_marginTop="10dp"
               android:layout_width="match_parent"
               android:layout_height="wrap_content"
               android:text="刘亦菲"
               android:textSize="25dp"/>
           <TextView
               android:layout_marginTop="10dp"
               android:layout_width="match_parent"
               android:layout_height="wrap_content"
               android:text="刘亦菲"
               android:textSize="25dp"/>
           <TextView
               android:layout_marginTop="10dp"
               android:layout_width="match_parent"
               android:layout_height="wrap_content"
               android:text="刘亦菲"
               android:textSize="25dp"/>
           <TextView
               android:layout_marginTop="10dp"
               android:layout_width="match_parent"
               android:layout_height="wrap_content"
               android:text="刘亦菲"
               android:textSize="25dp"/>
           <TextView
               android:layout_marginTop="10dp"
               android:layout_width="match_parent"
               android:layout_height="wrap_content"
               android:text="刘亦菲"
               android:textSize="25dp"/>
           <TextView
               android:layout_marginTop="10dp"
               android:layout_width="match_parent"
               android:layout_height="wrap_content"
               android:text="刘亦菲"
               android:textSize="25dp"/>
           <TextView
               android:layout_marginTop="10dp"
               android:layout_width="match_parent"
               android:layout_height="wrap_content"
               android:text="刘亦菲"
               android:textSize="25dp"/>
       </LinearLayout>

   </ScrollView>


</RelativeLayout>


我的解答思路和尝试过的方法
我想要达到的结果
  • 写回答

1条回答 默认 最新

  • 不会写代码的猴子 Android领域优质创作者 2022-03-08 16:57
    关注

    fragment设置个背景,然后充满布局

    评论

报告相同问题?

问题事件

  • 创建了问题 3月8日

悬赏问题

  • ¥20 指导如何跑通以下两个Github代码
  • ¥15 大家知道这个后备文件怎么删吗,为啥这些文件我只看到一份,没有后备呀
  • ¥15 C++为什么这个代码没报错运行不出来啊
  • ¥15 一道ban了很多东西的pyjail题
  • ¥15 关于#r语言#的问题:如何将生成的四幅图排在一起,且对变量的赋值进行更改,让组合的图漂亮、美观@(相关搜索:森林图)
  • ¥15 C++识别堆叠物体异常
  • ¥15 微软硬件驱动认证账号申请
  • ¥15 GPT写作提示指令词
  • ¥20 根据动态演化博弈支付矩阵完成复制动态方程求解和演化相图分析等
  • ¥15 华为超融合部署环境下RedHat虚拟机分区扩容问题