【发布时间】:2016-12-22 08:11:11
【问题描述】:
我的应用中有这个 XML 布局,其中包含 ListView 和 CardView,但 CardView 内容有时隐藏在屏幕下方,我想将滚动应用到整个布局。
<?xml version="1.0" encoding="utf-8" ?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:orientation="vertical"
android:weightSum="2">
<include
android:id="@id/tool"
layout="@layout/toolbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<ListView
android:id="@+id/lvcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_below="@+id/toolbar"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="50dp" />
<android.support.v7.widget.CardView
android:id="@+id/cardView3"
android:layout_width="match_parent"
android:layout_height="160dp"
android:layout_below="@+id/lvcontent"
android:layout_margin="16dp"
android:layout_weight="0.2"
app:layout_anchorGravity="bottom"
card_view:cardCornerRadius="4dp"
card_view:contentPadding="8dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tvcusttest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="What Customers are Saying"
android:textColor="#000"
android:textSize="16dp" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@+id/tvcusttest"
android:background="@android:color/darker_gray"
android:paddingLeft="3dp"
android:paddingRight="3dp" />
</RelativeLayout>
<com.viewpagerindicator.CirclePageIndicator
android:id="@+id/cpiBanner"
android:layout_width="fill_parent"
android:layout_height="15dp"
android:layout_gravity="bottom|center_horizontal"
android:layout_marginBottom="7dp"
android:layout_marginTop="15dp"
android:padding="1dp"
app:fillColor="#ffffff"
app:pageColor="#80cccccc" />
<android.support.v4.view.ViewPager
android:id="@+id/vpCustomerTestimonials"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</android.support.v7.widget.CardView>
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="30dp"
android:layout_weight="1"></View>
<LinearLayout
android:id="@+id/content"
android:layout_width="fill_parent"
android:layout_height="61dp"
android:layout_alignParentBottom="true"
android:layout_below="@+id/cardView3"
android:gravity="center_vertical"
android:orientation="horizontal"
android:weightSum="1">
<Button
android:id="@+id/btnviewcart"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_weight="0.5"
android:background="@color/selecteditem"
android:text="View Cart"
android:textAlignment="center"
android:textAllCaps="true"
android:textColor="#ffffff"
android:textSize="23sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
出了什么问题?当屏幕尺寸较小时,半布局隐藏在屏幕下方。我只想对此应用滚动行为。我会非常感谢你。
【问题讨论】:
-
将布局放在滚动视图中,使用 recyclerview 而不是列表视图可能会解决您的问题。如果您使用的是列表视图本身,那么您必须分别处理滚动视图的滚动和滑动
-
我必须使用listview本身,所以建议相应
-
当我将滚动视图放在线性布局上方时,它只会滚动列表视图,而卡片视图内容仍然隐藏在屏幕下方
-
你必须为它使用页脚视图,将cardview xml内容放在页脚视图中,然后将其添加到列表视图中。 @neha
-
但是当我使用页脚查看时,卡片视图的内容会变成黑色背景
标签: android listview android-scrollview