【问题标题】:Android Layout: fragment with listview layout is not fullscreenAndroid 布局:具有列表视图布局的片段不是全屏
【发布时间】:2016-03-09 09:52:34
【问题描述】:

我在包含列表视图的片段中遇到了这个布局问题;列表视图未扩展到 match_parent

我有一个包含几个项目的列表视图。布局仅针对未覆盖全屏的元素显示。

我尝试在所有布局中使用 ma​​tch_parent,但仍然无法解决问题。

下面是我的带有列表视图的片段布局

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/borevalues" 
       >


        <ListView android:id="@+id/listofboreranges" 
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:divider="@null" 
            android:scrollbars="none"
         />


</RelativeLayout>

下面是我的容器布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
  >

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

</RelativeLayout>

这就是我使用 listview 调用片段的方式

FragmentManager fragmentManager = getFragmentManager();
                    FragmentTransaction ft = fragmentManager.beginTransaction();
                    FragmentChangeActivity.fragmentStack.lastElement().onPause();
                    ft.hide(FragmentChangeActivity.fragmentStack.lastElement());
                    ft.add(R.id.content_frame, boreranges);
                    FragmentChangeActivity.fragmentStack.push(boreranges);
                    ft.commit();

有什么解决办法吗?

如下图

Fragment A 有这个橙色和绿色的按钮,当我单击它时,它将转到具有列表视图的 Fragment B。 我想要片段 B 中的列表视图全屏并覆盖绿色和橙色。

【问题讨论】:

  • 你能贴出你的屏幕图片吗
  • @PhanVănLinh 抱歉,我无法公开分享屏幕截图。发生的事情是当我从一个片段转到此列表片段时,列表视图仅覆盖半屏,因为它只有 4 个项目,在后台我仍然可以看到我调用此列表片段的旧片段。
  • 也许您可以隐藏屏幕中不想发布的部分
  • 你能绑定listview的宽高吗
  • @PhanVănLinh 你是什么意思我的绑定?。我需要全屏

标签: android android-layout listview android-fragments android-studio


【解决方案1】:

尝试使用此代码

MyFragment boreranges= new MyFragment();

FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.add(R.id.mainframe, boreranges);
transaction.commit();

【讨论】:

  • 这就是我以前的做法
  • 在xml中测试listview的背景颜色并检查设计是否会覆盖整个屏幕,请检查n让我知道...
  • 嘿,我在 xml 中为 listview 设置了红色,但是当我运行应用程序时,我无法看到重新,发生了什么
  • 它进入设计视图???我的意思是在工作室本身有 xml 的设计和文本,签入可见的设计并且它是否覆盖全屏..?
  • 是的,在演播室中它全屏显示红色背景,但是当我在设备中运行时,我没有看到任何红色
猜你喜欢
  • 2016-10-13
  • 1970-01-01
  • 1970-01-01
  • 2017-04-15
  • 1970-01-01
  • 2015-08-13
  • 2016-08-08
  • 1970-01-01
  • 2013-02-07
相关资源
最近更新 更多