android - 为什么这个列表/ ScrollView 没有填充父级?

标签 android listview fullscreen

我在这里遵循了一些说明:http://saigeethamn.blogspot.com/2010/04/custom-listview-android-developer.html

我下面的示例全屏显示列表。这就是我想要我做的。我做错了什么?

示例结果:examples result

我的结果:

my result

我遵循的示例使用了 2 个 xml 布局。 1 为页面。 1 为列表。

页面:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout 
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ListView android:id="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000fff"
android:layout_weight="2"
android:drawSelectorOnTop="false">
</ListView>
<TextView  android:id="@id/android:empty"
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="#FFff00"
android:text="No data"
/>
</LinearLayout>
</ScrollView>

这是列表的 xml:

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

<TextView android:id="@+id/tvAccountName"         
android:textSize="16sp"         
android:textStyle="bold" 
android:textColor="#FFFF00"        
android:layout_width="fill_parent"         
android:layout_height="fill_parent"/>
<TextView android:id="@+id/tvAccountType" 
android:typeface="sans"
android:textSize="14sp"
android:textStyle="italic"
android:layout_width="wrap_content" 
android:layout_height="wrap_content"/>
<TextView android:id="@+id/tvAccountBalance"         
android:textSize="12sp"         
android:textStyle="bold"      
android:layout_width="wrap_content"         
android:layout_height="fill_parent"/>
</LinearLayout>

这是 list 中的条目:

   <activity android:name=".listAccountsPage"
              android:label="@string/app_name"
              >
        <intent-filter>
            <action android:name="com.ourcreditunion.ourcumobile.LISTACCOUNTS" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
</activity>

那么我做了什么导致它不全屏?

最佳答案

就像 @adamp 所说 - 不要将 ListView 放在 ScrollView 中。哪一个要滚动? 您的 xml 也需要更简单。尝试这样的事情:

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

如果想要彩色背景,请在RelativeLayout中设置background属性

关于android - 为什么这个列表/ ScrollView 没有填充父级?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6324515/

相关文章:

java - 在 Android JUnit 测试中加载 native 库

带有圆角的Android CardView显示灰色角落

java - Java Android DC音频输出

java - 带定制适配器的 NPE

android - 如何以编程方式检测 Mi 设备中的全屏手势模式

android - 在 Android ICS 上隐藏系统栏的简单方法

fullscreen - vmware中如何设置最大全屏?

android - 有没有办法禁用除可扩展 ListView Android中单击的父 View 之外的所有父 View ?

java - 如何将行动态添加到 ListView ?

asp.net - 我可以使用动态 GroupItemCount 创建 ListView 吗?