Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.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_Xml_Android Layout_Listview - Fatal编程技术网

Android listview不显示任何内容并隐藏数据

Android listview不显示任何内容并隐藏数据,android,xml,android-layout,listview,Android,Xml,Android Layout,Listview,我想在列表中水平显示七个文本视图和两个按钮。我的列表适用于五个文本视图,如果添加更多控件,则它不会显示任何内容。我的代码是正确的,我试图用xml更改所有内容,但在屏幕上看不到任何内容。请帮助我如何使用正确的格式 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width

我想在列表中水平显示七个文本视图和两个按钮。我的列表适用于五个文本视图,如果添加更多控件,则它不会显示任何内容。我的代码是正确的,我试图用xml更改所有内容,但在屏幕上看不到任何内容。请帮助我如何使用正确的格式

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

 <!-- Third header line and column headings -->
 <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="30dp"
    android:orientation="horizontal"
    android:background="#A1E9FF">

    <TextView android:id="@+id/column_header1"
      android:layout_width="0dp"
      android:layout_height="wrap_content"
      android:layout_weight="1"
        />
    <TextView android:id="@+id/column_header2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        />
 </LinearLayout>  

 <ListView
    android:id="@+id/listView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" 
    android:divider="#b5b5b5"
    android:dividerHeight="2dp">
</ListView>


我认为您的问题可能是因为您试图显示的项目多于屏幕上的空间。为了对抗这种效果,你可以使用一个可以让你水平滚动来查看所有视图的工具

另外,方向属性在RelativeLayout上不起作用,我建议您使用



PS:我懒得删除RelativeLayout的特定属性,例如:alignTop、alignParentRight等。因此,请随意删除这些属性。

如Torque203所述,
方向
属性对
RelativeLayout
无效

相对视图未按预期工作的另一个原因是,定义子视图的相对位置时,顺序很重要。
RelativeLayout
膨胀时,XML从上到下读取,并且新的子视图只能指定为相对于之前已定义的其他子视图

考虑你的第二个文本视图:

<TextView
    android:id="@+id/morn_even"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="31dp"
    android:layout_toRightOf="@+id/doc_code"
    android:text="morn_even"
    android:textColor="#000"
    android:textSize="15dp" />

您指定此视图是视图
doc\u code
的“toRightOf”,但
RelativeLayout
还不知道此
doc\u code
视图的任何信息,因为您直到XML的末尾才定义它

不过,这里并不只有你一个人。很多人在第一次开始玩
RelativeLayout
时就误解了这一点

需要理解的关键是,
RelativeLayout
将只实现锚定到已定义和固定位置的视图的相对位置规则

例如考虑一个新的空<代码> RealValayOut<<代码>:

  • 我们向它添加了一个新的子视图
    a
对于第一个子项,我们只能指定相对于其父项的位置规则。
如果我们没有定义任何相对于其父项的位置规则,则默认情况下,它将放置在左上角

  • 我们添加了一个新的子视图
    B
对于该子视图,我们可以指定相对于其父视图或相对于现有视图的位置规则
A

我们无法指定与视图
C
相关的任何尚未定义的位置规则


在一个现实世界的例子中,假设我在排队让人们合影,首先我告诉吉姆站在照片的中心。如果我说“好的,安妮塔,你站在莉兹的右边”,你要么只是滑稽地看着我,要么说“但我还不知道莉兹应该站在哪里!”

我很感激你的代码。但这对我来说并不管用。我在水平方向和垂直方向上都试过了,但还是得到了空屏幕。
<?xml version="1.0" encoding="utf-8"?>

<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/plan_date"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="21dp"
        android:layout_toRightOf="@+id/Plan_no"
        android:text="plan date "
        android:textColor="#000"
        android:textSize="15dp" />

    <TextView
        android:id="@+id/morn_even"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="31dp"
        android:layout_toRightOf="@+id/doc_code"
        android:text="morn_even"
        android:textColor="#000"
        android:textSize="15dp" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_marginRight="12dp"
        android:layout_toLeftOf="@+id/button2"
        android:text="Visited"
        android:textColor="#000" />

    <TextView
        android:id="@+id/ff_code"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="30dp"
        android:layout_toRightOf="@+id/morn_even"
        android:text="ff code"
        android:textColor="#000"
        android:textSize="15dp" />

    <TextView
        android:id="@+id/speciality"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/ff_code"
        android:layout_marginLeft="22dp"
        android:layout_toRightOf="@+id/ff_code"
        android:text="speciality"
        android:textColor="#000"
        android:textSize="15dp"/>

    <TextView
        android:id="@+id/mon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="30dp"
        android:layout_toRightOf="@+id/plan_date"
        android:text="mon"
        android:textColor="#000"
        android:textSize="15dp" />

    <TextView
        android:id="@+id/Plan_no"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignTop="@+id/textView1"
        android:layout_marginLeft="17dp"
        android:text="plan no"
        android:textColor="#000"
        android:textSize="15dp" />

    <TextView
        android:id="@+id/doc_code"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="26dp"
        android:layout_toRightOf="@+id/mon"
        android:text="doc_code"
        android:textColor="#000"
        android:textSize="15dp" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignTop="@+id/textView1"
        android:text="Not Visited"
        android:textColor="#000" />

</LinearLayout>
</HorizontalScrollView>
<TextView
    android:id="@+id/morn_even"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="31dp"
    android:layout_toRightOf="@+id/doc_code"
    android:text="morn_even"
    android:textColor="#000"
    android:textSize="15dp" />