如何在给定 wrap_content 时摆脱 listView 中的滚动,尽管有足够的 space?
How to get rid of scroll in listView enenthough there is enough space when given wrap_content?
我在列表视图中滚动,即使列表视图下面有足够的 space。身高是 WRAP_CONTENT。由于我的设计,我无法给它 fill_parent 或 match_parent。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white" >
<RelativeLayout
android:id="@+id/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/header_back_blue"
android:gravity="center_vertical"
android:padding="10dp" >
<ImageView
android:id="@+id/first_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true" />
<TextView
android:id="@+id/header_title_text"
style="@style/headerBlueText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Home" />
<ImageView
android:id="@+id/last_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:onClick="openSettings"
android:src="@drawable/settings_icon" />
</RelativeLayout>
<TabHost
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/header"
android:background="@android:color/transparent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:background="@color/listview_back_grey" >
<RelativeLayout
android:id="@+id/rl_settings"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/settings_bg"
android:visibility="gone" >
<!-- Here I am getting scroll -->
<ListView
android:id="@+id/setting"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="@color/white"
android:divider="@color/settings_divider"
android:dividerHeight="2dp"
android:paddingLeft="15dp"
android:paddingRight="15dp" >
</ListView>
</RelativeLayout>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="visible" />
</FrameLayout>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:background="@android:color/transparent"
android:divider="@null" />
</LinearLayout>
</TabHost>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="@android:color/transparent"
android:onClick="openAddNewTask"
android:src="@drawable/center_circle" />
</RelativeLayout>
抱歉,由于声誉较低,我无法分享图片
你不应该为你的列表视图使用 wrap_content。你可能应该改变你的布局。也许使用重量来获得所需的尺寸,就像这里建议的那样:
这里
如果您根本不希望列表滚动,您可能不应该使用列表。也许尝试使用线性布局并将其填充到您的代码中。
我在列表视图中滚动,即使列表视图下面有足够的 space。身高是 WRAP_CONTENT。由于我的设计,我无法给它 fill_parent 或 match_parent。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white" >
<RelativeLayout
android:id="@+id/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/header_back_blue"
android:gravity="center_vertical"
android:padding="10dp" >
<ImageView
android:id="@+id/first_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true" />
<TextView
android:id="@+id/header_title_text"
style="@style/headerBlueText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Home" />
<ImageView
android:id="@+id/last_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:onClick="openSettings"
android:src="@drawable/settings_icon" />
</RelativeLayout>
<TabHost
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/header"
android:background="@android:color/transparent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:background="@color/listview_back_grey" >
<RelativeLayout
android:id="@+id/rl_settings"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/settings_bg"
android:visibility="gone" >
<!-- Here I am getting scroll -->
<ListView
android:id="@+id/setting"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:background="@color/white"
android:divider="@color/settings_divider"
android:dividerHeight="2dp"
android:paddingLeft="15dp"
android:paddingRight="15dp" >
</ListView>
</RelativeLayout>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="visible" />
</FrameLayout>
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:background="@android:color/transparent"
android:divider="@null" />
</LinearLayout>
</TabHost>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="@android:color/transparent"
android:onClick="openAddNewTask"
android:src="@drawable/center_circle" />
</RelativeLayout>
抱歉,由于声誉较低,我无法分享图片
你不应该为你的列表视图使用 wrap_content。你可能应该改变你的布局。也许使用重量来获得所需的尺寸,就像这里建议的那样: 这里
如果您根本不希望列表滚动,您可能不应该使用列表。也许尝试使用线性布局并将其填充到您的代码中。