Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/225.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android:ListView推出了它下面的所有内容_Android_Android Layout_Listview_Android Fragments - Fatal编程技术网

Android:ListView推出了它下面的所有内容

Android:ListView推出了它下面的所有内容,android,android-layout,listview,android-fragments,Android,Android Layout,Listview,Android Fragments,在我的应用程序中,有一个带有三个片段的选项卡式活动。第一个片段具有创建新任务的表单,第二个片段具有所有已保存任务的列表,第三个片段将在从第二个片段的列表中选择时显示任务的注释。第三个片段也应该像聊天活动一样,当您键入评论并点击发送按钮时,它会发布评论。第三个片段的XML布局如下所示: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk

在我的应用程序中,有一个带有三个
片段的选项卡式活动。第一个片段具有创建新任务的表单,第二个片段具有所有已保存任务的列表,第三个片段将在从第二个片段的列表中选择时显示任务的注释。第三个
片段
也应该像聊天活动一样,当您键入评论并点击发送按钮时,它会发布评论。第三个
片段的XML布局如下所示:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:background="@android:color/darker_gray"
android:orientation="vertical"
tools:context="com.example.ishita.assigntasks.CommentsFragment">

<TextView
    android:id="@+id/frag_task_details"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#dd55ff"
    android:padding="10dp" />

<ListView
    android:id="@+id/frag_comment_list"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:transcriptMode="normal" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:background="@android:color/white">

    <EditText
        android:id="@+id/frag_msg_edit"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:inputType="textMultiLine"
        android:layout_weight="1" />

    <ImageButton
        android:id="@+id/frag_send_btn"
        style="?android:attr/buttonStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0"
        android:background="@android:color/background_light"
        android:contentDescription="@string/send_btn"
        android:src="@android:drawable/ic_menu_send" />

</LinearLayout>

</LinearLayout>

如您所见,有一个
文本视图
和一个
列表视图
,下面是另一个
线性布局
。下面是它的外观(紫色条是
TextView
):

下面是它的实际外观:

文本视图
显示在
列表视图
上方,但
线性布局
不显示。不过,它就在那里。如果我在最外层的线性布局上使用android:layout_marginBottom=“20dp”
,它确实会出现,但是
操作栏
会向上滚动并与通知栏重叠,这样
操作栏
上的标题和通知栏上的通知都可以同时看到,而且都不清晰

我搜索了很多,这似乎是一个常见的问题,但没有一个解决方案对我有帮助。相信我,我尽我所能找到了。我试着用一个
FrameLayout
,用一个
RelativeLayout
代替最外层的
LinearLayout
,用两个
LinearLayout
包装整个东西,一个包装
TextView
ListView
,另一个包装
EditText
ImageButton
,等等。,但是没有任何东西能够显示
列表视图下的底部
线性布局
。我甚至试着在片段启动时将焦点设置在
EditText
,这样键盘就会显示出来,我就可以打字了,但即使这样也无济于事

注意:另一方面,如果我在
活动
上使用完全相同的布局,则底部的
线性布局
会显示出它应该显示的内容


我找不到那只虫子。请帮忙

正如您在listview布局中给布局权重1一样,它占用了整个可用空间。为了摆脱这种情况,你必须给出一些静态高度,或者以正确的方式使用布局权重

<ListView
android:id="@+id/frag_comment_list"
android:layout_width="match_parent"
android:layout_height="500dp"
android:transcriptMode="normal" />

或者像这样试试

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:background="@android:color/darker_gray"
android:orientation="vertical"
tools:context="com.example.ishita.assigntasks.CommentsFragment">

   <TextView
   android:id="@+id/frag_task_details"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:background="#dd55ff"
   android:padding="10dp" />
  <LinearLayout
  android:layout_width="match_parent"
  android:layout_height="0dp"
  android:layout_weight="1"
    android:orientation="vertical"
  android:background="@android:color/white">
  <ListView
android:id="@+id/frag_comment_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:transcriptMode="normal" />
</LinearLayout>
 <LinearLayout
android:layout_width="match_parent"
 android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
android:background="@android:color/white">

<EditText
    android:id="@+id/frag_msg_edit"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:inputType="textMultiLine"
    android:layout_weight="1" />

<ImageButton
    android:id="@+id/frag_send_btn"
    style="?android:attr/buttonStyleSmall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="0"
    android:background="@android:color/background_light"
    android:contentDescription="@string/send_btn"
    android:src="@android:drawable/ic_menu_send" />

   </LinearLayout>

   </LinearLayout>

看起来您的工具栏在不降低其高度的情况下向下推动片段布局。我不知道为什么会发生这种情况(这里没有根布局代码)

作为一种解决方法,您可以将碎片布局底部边距设置为
?attr/actionBarSize

全部


谢谢你的回复。我现在通过反复试验找到了一个解决办法,我想我应该为其他面临同样问题的人发布答案。我在内部
LinearLayout
上设置了
android:layout\u marginBottom=“50dp”
(环绕注释栏的一个--
EditText
ImageButton
)。不知何故,这正确地设置了布局,并且片段在棒棒糖和果冻豆操作系统中都能正常工作。我还没有在其他操作系统版本上测试过。

首先,你应该阅读,什么是
layout\u weight
,以及它是如何工作的

您将
layout\u weight
指定给
ListView
作为
1
,这意味着它覆盖了整个高度。只需将其更改为
0.7
,或者您想要的任何比例(小于
1
)即可解决问题

<ListView
    android:id="@+id/frag_comment_list"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.7"
    android:transcriptMode="normal" />


我已经发布了我的答案,请看一下。如果它不起作用,一定要让我知道你想看起来像什么吗?@pRaNaY不,我的目标是在屏幕底部有一个评论栏。请参阅我发布的答案。我在我的应用程序中也做了同样的事情。试试看……这很奇怪,因为我在片段中检查了它,你的布局很好。看起来应该如此。我试过4.0和5.1版本。嗯……我也试过果冻豆和棒棒糖,但在选项卡式活动中,这两个版本都不起作用(嗯……一些工具栏问题?它会向下推布局。你能把底部的线性布局(比工具栏)调大些吗?)要检查这一点?解释得很好!但是既然您编辑了以前的答案,有没有办法删除我的第一条评论?:由于项目规范,PI不能在任何
视图上使用固定高度。您的第二个解决方案只会在列表和评论栏之间50-50地分割屏幕。这绝对不是我想要的“我正在努力实现。我希望条形图位于屏幕底部。如果屏幕高度低于
500dp
,它将如何显示?如果这是一个工具栏问题,您应该使用?attr/actionBarSize而不是50dp。@AlexandrShutko哦!是的,谢谢!这是一个解决方案,而不是我的解决方法。如果您发布作为回答,我将接受它。:)不要设置
margin
而是尝试
android:layout\u weight=“0.7”
ListView
,我想这是正确的解决方案。@ELITE。为什么是0.7?权重为1、高度为0的布局占用所有可用空间。他的问题在父布局中。其工具栏向下推送所有布局,而不降低高度。我改变了答案。@AlexandrShutko谢谢。哦,还有更正:*她的问题;)我尝试了所有这些,但都没有成功。不是重量问题。阅读亚历山大·舒特科的回答。