Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/219.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 在活动底部显示列表视图_Android_Listview - Fatal编程技术网

Android 在活动底部显示列表视图

Android 在活动底部显示列表视图,android,listview,Android,Listview,我刚开始在Android上开发,所以请容忍我。我有一个活动,它显示了今天的一些天气数据,我想在活动底部列出未来7天的更多天气数据,如下所示: 然而,我对实现这一目标的最佳方式感到困惑。我曾想过使用ListView,但我对如何使用它们感到困惑。根据我收集的信息,我需要在res/layout中创建一个ListView布局,然后在我的主要活动中使用一个片段,它的布局设置为我刚才创建的ListView布局。对吗?或者更简单的解决方案是将ListView放在我的主要活动的底部 或者,我是否使用了完全错误

我刚开始在Android上开发,所以请容忍我。我有一个活动,它显示了今天的一些天气数据,我想在活动底部列出未来7天的更多天气数据,如下所示:

然而,我对实现这一目标的最佳方式感到困惑。我曾想过使用ListView,但我对如何使用它们感到困惑。根据我收集的信息,我需要在
res/layout
中创建一个ListView布局,然后在我的主要活动中使用一个片段,它的布局设置为我刚才创建的ListView布局。对吗?或者更简单的解决方案是将ListView放在我的主要活动的底部


或者,我是否使用了完全错误的控件来完成我想做的事情?

通过以下代码,您可以非常轻松地制作此布局:

<Relativelayout...>

    <EditText android="@+id/edit1"
      android:alignParentTop="true"
      ... />

    <LinearLayout android:id="@+id/YOUR_MIDDLE_DATA"
      android:above="@+id/listview1"
      android:below="@+id/edit1" ...>
      ...
      ...
    </Linearlayout>

    <Listview android:id="@+id/listview1"
      android:above="@+id/txt1"
      ... />

    <Textview android:id="@+id/txt1"
      ...
      android:alignParentBottom="true" />
</RelativeLayout>

...
...
您还可以使用重量进行自定义


希望这能对您有所帮助。

以下面的XML为例。在这个(来自我的一个应用程序的实际XML)中,我在
列表视图
上方有一个较小的
编辑文本
,但您可以将其更改为您需要的其他内容。这从本质上说明了您可以在顶部或底部拥有一个
列表视图
,以及一些其他内容。(我在已删除的
列表视图
后面有Admob代码)

利与弊与前面的例子几乎相反

无论在
片段
活动
中使用哪种方法,这两种方法都将起作用

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="0dip"
    android:layout_weight="1"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/phone_thing_comment_bg"
        android:gravity="center"
        android:paddingBottom="5dp"
        android:paddingLeft="9dp"
        android:paddingRight="9dp"
        android:paddingTop="5dp" >

        <EditText
            android:id="@+id/editFilterList"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_margin="4dp"
            android:background="@drawable/phone_thing_comment_box"
            android:drawableLeft="@drawable/filter_search_icon"
            android:drawablePadding="5dp"
            android:hint="Type Friends Name"
            android:inputType="text"
            android:maxLines="1"
            android:textColor="#ff333333"
            android:textColorHint="#ff78797d"
            android:textCursorDrawable="@null" >
        </EditText>
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <ListView
            android:id="@+id/list"
            android:layout_width="fill_parent"
            android:layout_height="0dip"
            android:layout_weight="1"
            android:cacheColorHint="@android:color/transparent"
            android:divider="#000000"
            android:dividerHeight="0dp"
            android:fadingEdge="none"
            android:persistentDrawingCache="scrolling"
            android:scrollbars="none" >
        </ListView>

        <TextView
            android:id="@android:id/empty"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:gravity="center"
            android:padding="10dp"
            android:text="@string/no_friends"
            android:textColor="#f1f1f1"
            android:textSize="15sp"
            android:textStyle="bold"
            android:visibility="gone" >
        </TextView>
    </LinearLayout>
</LinearLayout>
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/phone_thing_comment_bg"
        android:gravity="center"
        android:paddingBottom="5dp"
        android:paddingLeft="9dp"
        android:paddingRight="9dp"
        android:paddingTop="5dp" >

        <EditText
            android:id="@+id/editFilterList"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_margin="4dp"
            android:background="@drawable/phone_thing_comment_box"
            android:drawableLeft="@drawable/filter_search_icon"
            android:drawablePadding="5dp"
            android:hint="Type Friends Name"
            android:inputType="text"
            android:maxLines="1"
            android:textColor="#ff333333"
            android:textColorHint="#ff78797d"
            android:textCursorDrawable="@null" >
        </EditText>
    </LinearLayout>