listfragment 与我的主抽屉重叠

2024-01-13

我是Android新手,我正在创建一个应用程序,并且我有一个列表片段问题,因为列表显示但它与标题栏重叠(我必须添加边距顶部来改变它),而且我正在使用抽屉并且当我尝试时要打开它在选项抽屉上显示的列表,请让我粘贴代码和图像,以便您可以了解更多信息:

xml代码:

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:weightSum="1">

    <ListView
        android:layout_width="match_parent"
        android:layout_height="420dp"
        android:id="@android:id/list"
        android:layout_weight="0.82"
        android:layout_marginTop="60dp" />
</LinearLayout>

列表片段代码:

  public class FragmentoPrincipalChofer extends ListFragment {
    private List<ParseObject> mViaje;
    private ListView mLista;

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {



        View x = inflater.inflate(R.layout.fragmento_principal_chofer, container, false);
        mLista = (ListView)x.findViewById(android.R.id.list);
        return x;

    }

    @Override
    public void onResume() {
        super.onResume();

        //obtener pedido de taxi
       ParseQuery<ParseObject> query = ParseQuery.getQuery("Viaje");
        query.whereEqualTo("chofer", "prueba3");
        query.addDescendingOrder("createdAt");
        query.findInBackground(new FindCallback<ParseObject>() {
            public void done(List<ParseObject> viajes, com.parse.ParseException e) {
                if (e == null) {
                    mViaje=viajes;
                    String[] nombreUsuarios = new String[mViaje.size()];
                    int i=0;
                    for (ParseObject viaje : mViaje){

                        nombreUsuarios[i] = viaje.getString("cliente");
                        i++;
                    }

                   ArrayAdapter<String> adaptador = new ArrayAdapter<String>(getListView().getContext(),android.R.layout.simple_list_item_1,nombreUsuarios);
                  mLista.setAdapter(adaptador);


                } else {

                }
            }
        });

    }
}

主抽屉代码:

public class DrawerPrincipal extends AppCompatActivity
        implements NavigationView.OnNavigationItemSelectedListener,FragmentoPrincipalUsuario.OnFragmentInteractionListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_drawer_principal);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        //cargar fragment principal usuario

        FragmentoPrincipalChofer fragmento=(FragmentoPrincipalChofer) getSupportFragmentManager().findFragmentByTag("fragmento");
        if (fragmento==null){
            fragmento=new FragmentoPrincipalChofer();
            android.support.v4.app.FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
            transaction.add(android.R.id.content,fragmento,"fragmento");
            transaction.commit();

        }
        /*
        FragmentoPrincipalUsuario principal = new FragmentoPrincipalUsuario();
        android.support.v4.app.FragmentTransaction FragmentTransaction =
                getSupportFragmentManager().beginTransaction();
        FragmentTransaction.replace(R.id.contenedor_principal,principal);
        FragmentTransaction.commit();
        */

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.setDrawerListener(toggle);
        toggle.syncState();

        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
        navigationView.setNavigationItemSelectedListener(this);
    }

    @Override
    public void onBackPressed() {
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        if (drawer.isDrawerOpen(GravityCompat.START)) {
            drawer.closeDrawer(GravityCompat.START);
        } else {
            super.onBackPressed();
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.pantalla_principal_usuario, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    @SuppressWarnings("StatementWithEmptyBody")
    @Override
    public boolean onNavigationItemSelected(MenuItem item) {
        // Handle navigation view item clicks here.
        int id = item.getItemId();

        if (id == R.id.cuenta) {
            // Handle the camera action
        } else if (id == R.id.historial_viajes) {

        } else if (id == R.id.contacto) {

        } else if (id == R.id.compartir) {

        } else if (id == R.id.version) {

        } else if (id == R.id.salir) {

        }

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawer.closeDrawer(GravityCompat.START);
        return true;
    }

    @Override
    public void onFragmentInteraction(Uri uri) {

    }
}

列表片段重叠 https://i.stack.imgur.com/Wn661.png

这里是activity_drawer_principal.xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

    <include
        layout="@layout/app_bar_drawer_principal"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_drawer_principal"
        app:menu="@menu/activity_pantalla_principal_usuario_drawer" />

</android.support.v4.widget.DrawerLayout>

这是app_bar_drawer_principal:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context=".DrawerPrincipal">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay"/>

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

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

    </FrameLayout>

    <include layout="@layout/content_drawer_principal" />

</android.support.design.widget.CoordinatorLayout>

你的问题是你用这一行将列表片段设置为整个视图 ID

// android.R.id.content is the WHOLE screen of your Activity
transaction.add(android.R.id.content,fragmento,"fragmento");
transaction.commit();

在 content_drawer_principal.xml 中创建一个 FrameLayout:

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

then do:

transaction.add(R.id.list_content,fragmento,"fragmento");
transaction.commit();

UPDATE

这里真正的问题是你告诉你的 FragmentTransaction 加载你的FragmentoPrincipalChofer into android.R.id.content这是一个保留的ID

android.R.id.content 为您提供视图的根元素,而无需知道其实际名称/类型/ID。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

listfragment 与我的主抽屉重叠 的相关文章

随机推荐

  • 如何获取与另一个像素成一定角度的像素值?

    我正在尝试实现一种方法 其中我必须获取所有这些像素的值 这些像素通过像素 i j 以一定角度形成一条线 考虑以下代码片段 sum image getpixel i 7 j 2 image getpixel i 6 j 2 image get
  • 递归二叉搜索树插入

    这是我的第一个 java 程序 但我已经使用 c 几年了 我写了我认为应该有效的内容 但实际上却无效 所以我有一个规定 必须为这个调用编写一个方法 tree insertNode value 其中 value 是一个 int 出于显而易见的
  • 从隔离函数调用异步函数

    我正在尝试从 Isolate 函数调用异步函数 class IsolateExample final ReceivePort port new ReceivePort IsolateExample Isolate spawn isolate
  • 如何在 laravel dompdf 中自定义字体和页面?

    我从这里得到 https github com barryvdh laravel dompdf https github com barryvdh laravel dompdf 我的控制器是这样的 public function listd
  • 如何绘制survreg(R的包生存)生成的生存曲线?

    我正在尝试根据生存数据拟合并绘制威布尔模型 该数据只有一个协变量 即从 2006 年到 2010 年运行的队列 那么 对于在后面的两行代码中添加什么来绘制 2010 年队列的生存曲线 有什么想法吗 library survival s lt
  • 如何在pygame中添加残像?

    由于角色移动是基于网格的 因此当角色从一个方格移动到另一个方格时 它们看起来有点奇怪 因为它们只是从一个方格出现到另一个方格 为了让动作感觉更自然 我想添加 残像 以便模拟平滑的动作 Demonstrational image Since
  • 多个 AsyncHttpClient get 请求填充一项活动

    我有一个 GameActivity 为了填充布局 我必须多次调用远程 API 并想知道使用 AsyncHttpClient 包完成此操作的最佳方法http loopj com android async http http loopj co
  • 我如何从网络元素获取文本并在控制台中打印(例如)

    我在从网页上的元素获取文本时遇到问题 我正在使用 TestCafe e2e 框架 想要将文本 Web 元素的内容打印到控制台 你能提供一些代码吗 const getInnerText ClientFunction gt homePage k
  • executionTimeout 在 asp.net mvc 上不起作用

    我尝试在 web config 中为 asp net mvc 应用程序设置executionTimeout
  • 数组指针什么时候有用?

    我可以声明 int ap N So ap是指向大小为 N 的 int 数组的指针 为什么这很有用 如果我将它传递给函数 它可以用它做哪些有用的事情 而它不能用指向数组内容的普通指针来做 C常见问题解答说 2 12 如何声明一个指向数组的指针
  • Gradle Xpp3 错误

    我在为发布版本执行 gradle 构建时收到此错误 错误 xpp3 定义的类与现在提供的类冲突 安卓 解决方案包括寻找更新版本或替代方案 没有同样问题的库 例如 httpclient使用HttpUrlConnection或者okhttp代替
  • Git 对 *.reg 文件显示“二进制文件 a... 和 b... 不同”

    有没有办法强制 Git 处理 reg文件作为文本 我正在使用 Git 来跟踪我的 Windows 注册表调整和 Windows 使用情况 reg对于这些文件 更新1 我让它运行差异 谢谢 安德鲁 然而 现在看起来像下面这样 这是编码问题吗
  • 我可以使用 AngularJs 指令将样式应用于伪元素吗

    我希望我在这里没有遗漏一些明显的东西 但我正在尝试学习 Angular 并且在尝试制定指令时遇到了问题 我正在尝试构建一个指令 该指令将从数据属性 背景图像 获取 url 并将其作为背景图像应用到伪元素 但我无法弄清楚如何定位 before
  • 在 GitLab TeamCity 中显示构建状态

    我已成功将 TeamCity 配置为自动从 GitLab 提取新签入的更改并构建它 下一步 我希望 GitLab 中的构建状态图标能够反映 TeamCity 的构建状态 在每次构建 TeamCity 构建时 GitLab 继续显示 buil
  • 程序接收信号SIGTRAP,跟踪/断点陷阱

    我正在调试一个 嵌入式 软件 我在一个函数上设置了一个断点 出于某种原因 一旦我到达该断点并且continue我总是回到该函数 这是一个初始化函数 只能调用一次 当我删除断点时 并且continue GDB 告诉我 Program rece
  • jQuery UI 主题和 HTML 表格

    有没有办法使用 jQuery CSS 主题来设置 HTML 表格 CSS 主题 我的所有组件看起来都属于同一组 除了 HTML 表格看起来不同 那里有很多资源 支持 ThemeRoller 的插件 jqGrid http www trira
  • django 表单发布请求在 __init__ 方法上引发错误

    我有一个 django 表单 它从视图中获取参数来根据用户实例初始化多项选择字段 加载模板时表单工作正常 当我提交表格时init表单中的方法会引发错误 My Model模型 py from django db import models f
  • Node.js 递归列出文件的完整路径[重复]

    这个问题在这里已经有答案了 各位晚安 我在使用一些简单的递归函数时遇到了麻烦 问题是递归列出给定文件夹及其子文件夹中的所有文件 目前 我已经成功使用一个简单的函数列出目录中的文件 fs readdirSync copyFrom forEac
  • 使用竞争检测器时可以跳过特定测试吗?

    Go Race Detector 的 goroutine 限制为 8192 至少在我的系统上 我运行的一项测试是查看我的服务器代码如何处理大量同时打开的连接 现在我正在尝试 gt 15000 当我跑步时go test race 因此 该特定
  • listfragment 与我的主抽屉重叠

    我是Android新手 我正在创建一个应用程序 并且我有一个列表片段问题 因为列表显示但它与标题栏重叠 我必须添加边距顶部来改变它 而且我正在使用抽屉并且当我尝试时要打开它在选项抽屉上显示的列表 请让我粘贴代码和图像 以便您可以了解更多信息