Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/205.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的RelativeLayout不';没有正确显示_Android_Listview_Android Relativelayout - Fatal编程技术网

Android 与ListView的RelativeLayout不';没有正确显示

Android 与ListView的RelativeLayout不';没有正确显示,android,listview,android-relativelayout,Android,Listview,Android Relativelayout,我要发疯了,想让一个相对的布局工作。我在ListView中遇到了一个问题,ListView总是显示一个空的空间,大约是一个ListView元素高度的两倍,独立于列表是否足够大,是否可以滚动(通常列表可以容纳4个元素,而不需要滚动) 为了解决这个问题,我正在尝试实现一个RelativeLayout。我有一个文本视图在顶部,一个在底部,我的ListVIEW是在中间。textView必须“粘”在我的listview上,在出现空白问题之前,我使用的是LinearLayout,现在我有了这个相对布局:

我要发疯了,想让一个相对的布局工作。我在ListView中遇到了一个问题,ListView总是显示一个空的空间,大约是一个ListView元素高度的两倍,独立于列表是否足够大,是否可以滚动(通常列表可以容纳4个元素,而不需要滚动)

为了解决这个问题,我正在尝试实现一个RelativeLayout。我有一个文本视图在顶部,一个在底部,我的ListVIEW是在中间。textView必须“粘”在我的listview上,在出现空白问题之前,我使用的是LinearLayout,现在我有了这个相对布局:

    <ScrollView
 xmlns:android="http://schemas.android.com/apk/res/android"
     android:background="@drawable/background"
     android:layout_height="fill_parent"
     android:layout_width="fill_parent">

     <LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="wrap_content"
      android:orientation="vertical"
      android:layout_height="fill_parent">

     ...
            <RelativeLayout android:layout_width="fill_parent"
                android:layout_height="fill_parent" >

                <TextView
                    android:id="@+datatrade/tv_itens"
                    android:layout_width="fill_parent" 
                    android:layout_height="wrap_content"
                    android:layout_alignParentTop="true"
                    android:text="Itens:" />

                <TextView
                    android:id="@+datatrade/tv_value"
                    android:layout_width="fill_parent" 
                    android:layout_height="wrap_content"
                    android:text="Value:" />                                        

                <ListView android:layout_width="fill_parent"
                    android:layout_height="200px"
                    android:layout_below="@datatrade/tv_itens"
                    android:layout_above="@datatrade/tv_value"
                    android:id="@+id/list_product"
                    />

            </RelativeLayout>
     ...

...
...
问题是,我只显示了我的第二个文本视图,带有“value:”,其他什么都没有! 所有其他的相关布局都被android忽略了

有人知道问题出在哪里吗?


 <TextView
                android:id="@+datatrade/tv_value"
                android:layout_width="fill_parent" 
                android:layout_height="wrap_content"
                android:text="Value:" />   
您尚未声明此文本视图的显示位置


您尚未声明此文本视图的显示位置

试试这个:

 <LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="wrap_content"
      android:orientation="vertical"
      android:layout_height="fill_parent">

            <RelativeLayout android:layout_width="fill_parent"
                android:layout_height="fill_parent" >

                <TextView
                    android:id="@+id/tv_itens"
                    android:layout_width="fill_parent" 
                    android:layout_height="wrap_content"
                    android:layout_alignParentTop="true"
                    android:text="Itens:" />

                <TextView
                    android:id="@+id/tv_value"
                    android:layout_width="fill_parent" 
                    android:layout_height="wrap_content"
                    android:text="Value:" 
                    android:layout_below="@+id/list_product"/>                                        

                <ListView android:layout_width="fill_parent"
                    android:layout_height="200dp"
                    android:layout_below="@+id/tv_itens"
                    android:id="@+id/list_product"
                    />

            </RelativeLayout>
</LinearLayout>

您需要告诉ListView位于第一个TextView之下,然后第二个TextView位于ListView之下

另外,您的id看起来有点奇怪,我在复制您的代码时收到警告,请尝试使用@+id来确保

最后,您不应该使用px作为大小,而应该使用相对的dp

试试这个:

 <LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="wrap_content"
      android:orientation="vertical"
      android:layout_height="fill_parent">

            <RelativeLayout android:layout_width="fill_parent"
                android:layout_height="fill_parent" >

                <TextView
                    android:id="@+id/tv_itens"
                    android:layout_width="fill_parent" 
                    android:layout_height="wrap_content"
                    android:layout_alignParentTop="true"
                    android:text="Itens:" />

                <TextView
                    android:id="@+id/tv_value"
                    android:layout_width="fill_parent" 
                    android:layout_height="wrap_content"
                    android:text="Value:" 
                    android:layout_below="@+id/list_product"/>                                        

                <ListView android:layout_width="fill_parent"
                    android:layout_height="200dp"
                    android:layout_below="@+id/tv_itens"
                    android:id="@+id/list_product"
                    />

            </RelativeLayout>
</LinearLayout>

您需要告诉ListView位于第一个TextView之下,然后第二个TextView位于ListView之下

另外,您的id看起来有点奇怪,我在复制您的代码时收到警告,请尝试使用@+id来确保


最后,您不应该使用px作为大小,而应该使用相对的dp

必须指定每个对象相互关联。否则,相对布局无法理解对象的位置,也就没有相关性

检查此项以了解对象之间的相关性以及如何定位它们

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:background="#CCE6FF">

<ScrollView android:id="@+id/ScrollView01"
    android:layout_width="wrap_content" android:layout_height="wrap_content">

    <TextView android:text="@+id/TextView01"    android:id="@+id/dialog_desc_textview"
        android:layout_width="wrap_content" android:layout_height="wrap_content" 
         android:textSize="18dip" android:textColor="#000000"/>

</ScrollView>

<Button android:id="@+id/dialog_goToDesc_button"  android:layout_below="@id/ScrollView01"
    android:layout_width="wrap_content" android:layout_height="wrap_content"
    android:text="Satın Al" />

<Button android:id="@+id/dialog_buy_button" android:layout_below="@id/ScrollView01"
    android:layout_toRightOf="@id/dialog_goToDesc_button" android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:text="Detaya git" />

<Button android:id="@+id/dialog_cancel_button"
    android:layout_toRightOf="@id/dialog_buy_button" android:layout_below="@id/ScrollView01"
    android:layout_width="wrap_content" android:layout_height="wrap_content"
    android:text="Kapat" />

</RelativeLayout>

必须指定每个对象相互关联。否则,相对布局无法理解对象的位置,也就没有相对性

检查此项以了解对象之间的相关性以及如何定位它们

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:background="#CCE6FF">

<ScrollView android:id="@+id/ScrollView01"
    android:layout_width="wrap_content" android:layout_height="wrap_content">

    <TextView android:text="@+id/TextView01"    android:id="@+id/dialog_desc_textview"
        android:layout_width="wrap_content" android:layout_height="wrap_content" 
         android:textSize="18dip" android:textColor="#000000"/>

</ScrollView>

<Button android:id="@+id/dialog_goToDesc_button"  android:layout_below="@id/ScrollView01"
    android:layout_width="wrap_content" android:layout_height="wrap_content"
    android:text="Satın Al" />

<Button android:id="@+id/dialog_buy_button" android:layout_below="@id/ScrollView01"
    android:layout_toRightOf="@id/dialog_goToDesc_button" android:layout_width="wrap_content"
    android:layout_height="wrap_content" android:text="Detaya git" />

<Button android:id="@+id/dialog_cancel_button"
    android:layout_toRightOf="@id/dialog_buy_button" android:layout_below="@id/ScrollView01"
    android:layout_width="wrap_content" android:layout_height="wrap_content"
    android:text="Kapat" />

</RelativeLayout>


我在我的文本视图中尝试了android:layout\u alignParentTop=“true”,但没有声明位置(这一个),所有内容都与原来一样,只显示了这个文本视图。对不起,我的问题。。你想在列表视图中添加页眉和页脚吗?然后用android:layout\u alignParentTop=“true”添加alread内容。你试过android:layout\u alignParentBottom=“true”吗?哦,是的,我忘了alignParentTop。我尝试了alignParentBottom,得到了相同的结果…我尝试了android:layout\u alignParentTop=“true”在我的文本视图中,没有声明位置(这一个),但一切仍然像以前一样,只显示了这个文本视图。对不起,我的问题。。你想在列表视图中添加页眉和页脚吗?然后用android:layout\u alignParentTop=“true”添加alread内容。你试过android:layout\u alignParentBottom=“true”吗?哦,是的,我忘了alignParentTop。我试了一下,我得到了同样的结果。。。