如何将listview设置到原来的位置?
How to set listview to its original position?
我已经花了足够的时间让它在我的列表视图中设置 align_parentBottom=true.
布局的属性“above
”
看起来很简单吧?不,不是。
请看这张图片,这样您就可以想象问题并对此有所了解。
当用户 scrolls listview
时,主页按钮@bottom 隐藏。
默认情况下,如果列表滚动处于空闲状态,主页按钮将保持原样。这需要完成。
所以我的问题是主页按钮 Visibility
变为 GONE
然后 listview
将整个 space 填充到底部意味着 MATCH_PARENT
,没关系。
但是当滚动达到空闲状态时 & Visibility
设置为 Visible
然后列表视图的最后一个项目 goes/hides 在主页按钮后面。
这意味着 listview
没有到达其原始位置,如图所示。
尝试以编程方式将列表的 "above" 属性 设置为主页按钮 align_parentBottom=true
。
还尝试将整个布局更改为线性布局并提供 weight=1
.
但是没有成功。任何帮助将不胜感激。
谢谢。
布局文件碎片:
<LinearLayout
android:id="@+id/llmain"
android:visibility="visible"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical">
<TextView
android:id="@+id/txtTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/d_10"
android:layout_marginTop="@dimen/d_5"
style="@style/text_size_title"
android:textColor="@color/black"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/d_10"
android:layout_marginRight="@dimen/d_10"
android:layout_marginTop="@dimen/d_5">
<TextView
android:id="@+id/txtDateTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/comment_n_time_color_text"
android:textSize="14sp" />
<LinearLayout
android:layout_width="@dimen/d_1"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/d_3"
android:layout_marginRight="@dimen/d_3"
android:background="@color/comment_n_time_color" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:src="@drawable/ic_like" />
<TextView
android:id="@+id/txtLike"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/d_3"
android:layout_marginRight="@dimen/d_3"
android:textColor="@color/comment_n_time_color_text"
android:textSize="14sp" />
<LinearLayout
android:layout_width="@dimen/d_1"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/d_3"
android:layout_marginRight="@dimen/d_3"
android:background="@color/comment_n_time_color" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:src="@drawable/comment" />
<TextView
android:id="@+id/txtComment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/d_3"
android:layout_marginRight="@dimen/d_3"
android:textColor="@color/comment_n_time_color_text"
android:textSize="14sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="@dimen/article_detail_separator"
android:layout_marginTop="@dimen/d_5"
android:background="@color/comment_n_time_color"></LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/d_10"
android:layout_marginTop="@dimen/d_5"
android:text="@string/article_comment"
android:textAppearance="?android:textAppearanceMedium"
android:textColor="@color/black"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/d_10"
android:layout_marginRight="@dimen/d_10"
android:layout_marginTop="@dimen/d_5"
android:orientation="horizontal">
<EditText
android:id="@+id/txt_message"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/d_10"
android:layout_weight="1"
android:hint="@string/article_comment_hint"
android:textColor="@color/black" />
<ImageView
android:id="@+id/img_send"
android:padding="@dimen/d_10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:src="@drawable/send_button" />
</LinearLayout>
<ListView
android:id="@+id/listview_comments"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:cacheColorHint="@null"
android:listSelector="@null">
</ListView>
</LinearLayout>
我的 Activity 布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/parent"
android:background="@android:color/white">
<include
android:id="@+id/toolbaar"
layout="@layout/partial_toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_alignParentTop="true" />
<View
android:layout_below="@+id/toolbaar"
android:id="@+id/viewline"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="@color/separator_color" />
<FrameLayout
android:layout_above="@+id/llbottom"
android:layout_below="@+id/viewline"
android:id="@+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent"></FrameLayout>
<LinearLayout
android:id="@+id/llbottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical">
<include
android:id="@+id/img_home_"
layout="@layout/home_icon_footer"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</RelativeLayout>
我认为您可以通过拥有一个父视图来解决您的问题,让我们只说一个相对视图,然后在该相对视图中有 三个不同的视图。所以它看起来像相对视图,然后在里面你可以有一个列表视图上方的元素视图,然后是一个带有列表视图的滚动视图,最后是另一个视图,可能是相对视图,然后是主页按钮并确保align_parentBottom=true.
你必须在底部放置一个布局(线性布局) "Wrap_content" 和 along_parentbottom=true 并在该布局内放置你的主页底部。
现在,当您将主页按钮可见性设置为 GONE 布局时,您的布局仍然存在,高度为 0,当您使其可见时,其内部布局因此列表不会覆盖整个部分。
我已经通过
解决了这个问题
listview.scrollTo(0 , homeBtn.getHeight());
当我得到最后一个项目或说当没有列表的第一个项目时,它实际上移动我的列表项目以向上 Y 方向滚动。
我已经花了足够的时间让它在我的列表视图中设置 align_parentBottom=true.
above
”
看起来很简单吧?不,不是。
请看这张图片,这样您就可以想象问题并对此有所了解。
当用户 scrolls listview
时,主页按钮@bottom 隐藏。
默认情况下,如果列表滚动处于空闲状态,主页按钮将保持原样。这需要完成。
所以我的问题是主页按钮 Visibility
变为 GONE
然后 listview
将整个 space 填充到底部意味着 MATCH_PARENT
,没关系。
但是当滚动达到空闲状态时 & Visibility
设置为 Visible
然后列表视图的最后一个项目 goes/hides 在主页按钮后面。
这意味着 listview
没有到达其原始位置,如图所示。
尝试以编程方式将列表的 "above" 属性 设置为主页按钮 align_parentBottom=true
。
还尝试将整个布局更改为线性布局并提供 weight=1
.
但是没有成功。任何帮助将不胜感激。
谢谢。
布局文件碎片:
<LinearLayout
android:id="@+id/llmain"
android:visibility="visible"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical">
<TextView
android:id="@+id/txtTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/d_10"
android:layout_marginTop="@dimen/d_5"
style="@style/text_size_title"
android:textColor="@color/black"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/d_10"
android:layout_marginRight="@dimen/d_10"
android:layout_marginTop="@dimen/d_5">
<TextView
android:id="@+id/txtDateTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/comment_n_time_color_text"
android:textSize="14sp" />
<LinearLayout
android:layout_width="@dimen/d_1"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/d_3"
android:layout_marginRight="@dimen/d_3"
android:background="@color/comment_n_time_color" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:src="@drawable/ic_like" />
<TextView
android:id="@+id/txtLike"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/d_3"
android:layout_marginRight="@dimen/d_3"
android:textColor="@color/comment_n_time_color_text"
android:textSize="14sp" />
<LinearLayout
android:layout_width="@dimen/d_1"
android:layout_height="match_parent"
android:layout_marginLeft="@dimen/d_3"
android:layout_marginRight="@dimen/d_3"
android:background="@color/comment_n_time_color" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:src="@drawable/comment" />
<TextView
android:id="@+id/txtComment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/d_3"
android:layout_marginRight="@dimen/d_3"
android:textColor="@color/comment_n_time_color_text"
android:textSize="14sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="@dimen/article_detail_separator"
android:layout_marginTop="@dimen/d_5"
android:background="@color/comment_n_time_color"></LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/d_10"
android:layout_marginTop="@dimen/d_5"
android:text="@string/article_comment"
android:textAppearance="?android:textAppearanceMedium"
android:textColor="@color/black"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/d_10"
android:layout_marginRight="@dimen/d_10"
android:layout_marginTop="@dimen/d_5"
android:orientation="horizontal">
<EditText
android:id="@+id/txt_message"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/d_10"
android:layout_weight="1"
android:hint="@string/article_comment_hint"
android:textColor="@color/black" />
<ImageView
android:id="@+id/img_send"
android:padding="@dimen/d_10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:src="@drawable/send_button" />
</LinearLayout>
<ListView
android:id="@+id/listview_comments"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:cacheColorHint="@null"
android:listSelector="@null">
</ListView>
</LinearLayout>
我的 Activity 布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/parent"
android:background="@android:color/white">
<include
android:id="@+id/toolbaar"
layout="@layout/partial_toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_alignParentTop="true" />
<View
android:layout_below="@+id/toolbaar"
android:id="@+id/viewline"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="@color/separator_color" />
<FrameLayout
android:layout_above="@+id/llbottom"
android:layout_below="@+id/viewline"
android:id="@+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent"></FrameLayout>
<LinearLayout
android:id="@+id/llbottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical">
<include
android:id="@+id/img_home_"
layout="@layout/home_icon_footer"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</RelativeLayout>
我认为您可以通过拥有一个父视图来解决您的问题,让我们只说一个相对视图,然后在该相对视图中有 三个不同的视图。所以它看起来像相对视图,然后在里面你可以有一个列表视图上方的元素视图,然后是一个带有列表视图的滚动视图,最后是另一个视图,可能是相对视图,然后是主页按钮并确保align_parentBottom=true.
你必须在底部放置一个布局(线性布局) "Wrap_content" 和 along_parentbottom=true 并在该布局内放置你的主页底部。 现在,当您将主页按钮可见性设置为 GONE 布局时,您的布局仍然存在,高度为 0,当您使其可见时,其内部布局因此列表不会覆盖整个部分。
我已经通过
解决了这个问题listview.scrollTo(0 , homeBtn.getHeight());
当我得到最后一个项目或说当没有列表的第一个项目时,它实际上移动我的列表项目以向上 Y 方向滚动。