繁体   English   中英

如何将listview设置为其原始位置?

[英]How to set listview to its original position?

我花了足够的时间使它的列表视图在align_parentBottom=true.的布局的setProperty“ abovealign_parentBottom=true.

好像很容易吧? 不,这不对。

请查看此图像,以便您可视化问题并对此有一些了解。

在此处输入图片说明

当用户scrolls listview ,主页按钮@bottom隐藏。

并且默认情况下,如果列表滚动处于空闲状态,则主页按钮保持不变。 这需要完成。

所以我的问题是,home键后Visibility那张GONE然后listview充满整个空间向着底部意味着MATCH_PARENT ,多数民众赞成罚款。

但是,当滚动到达空闲状态且“ Visibility设置为“ Visible ,列表视图的最后一项将进入/隐藏在“主页”按钮后面。

这意味着listview并没有到达Image所示的原始位置。

通过以编程方式将列表的“ 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>

和我的活动布局:

<?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>

我认为您可以通过拥有一个父视图,只说一个相对视图,然后在该相对视图中拥有三个不同的视图来解决您的问题。 因此,它看起来像是相对视图,然后在内部,您可以在列表视图上方有一个元素视图,然后是一个包含列表视图的ScrollView,最后是主页按钮之后的另一个视图(可能是相对视图),并确保到align_parentBottom = true

您必须在底部放置一个布局(Linearlayout),并带有“ Wrap_content”和adround_parentbottom = true,并且在该布局内部将您的首页放置在底部。 现在,当您将主页按钮的可见性设置为GONE布局时,您的布局仍会以0高度存在,并且当使其可见时,它的内部布局便会出现,因此列表不会覆盖整个部分。

我已经通过解决此问题

listview.scrollTo(0,homeBtn.getHeight());

当我得到最后一个项目或说当列表中没有第一个项目时,它实际上将我的列表项目移动到Y方向上。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM