【问题标题】:Why ImageView of screen is not drawn为什么不绘制屏幕的ImageView
【发布时间】:2016-07-28 08:51:40
【问题描述】:

我需要在包含RecyclerViewImageView 的布局上创建反弹动画。为了简化解释,这里是我当前布局的说明:

RecyclerView (Red) 占据所有屏幕尺寸,并在其下方放置一开始看不到的ImageView (Green)。这两个视图包含在具有垂直方向的 LinearLayout (Blue) 中。

我想要做的是将LinearLayout 向上移动 50dp,然后使用反弹动画将其放回原处,以便图像视图仅在此动画期间可见。

问题是当我用这个代码提出LinearLayout时:

mLayout.postDelayed(new Runnable() {
        @Override
        public void run() {
            mLayout.animate().y(-500f);
        }
    }, 1000);

ImageView 没有显示,当我使用 DDMS 并在移动动画之后获取 XML 布局的快照时,看起来图像甚至不是布局的一部分。

更新: xml 布局:

<?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:tools="http://schemas.android.com/tools"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/white"
            android:orientation="vertical"

            android:animateLayoutChanges="true"
            android:theme="@style/AppTheme.MyTopics.Theme"
            tools:mContext=".ui.fragments.MyTopicsFragment">

<include
    android:id="@+id/toolbar_container"
    layout="@layout/toolbar_timeline_container"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

    <LinearLayout
    android:id="@+id/layout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:layout_below="@id/toolbar_container">

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipe_refresh"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <com.lsjwzh.widget.recyclerviewpager.RecyclerViewPager
            android:id="@+id/vertical_recycler_view"
            style="@style/NoOverScrollStyle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/white"
            app:rvp_singlePageFling="true"/>

    </android.support.v4.widget.SwipeRefreshLayout>

    <ImageView
        android:id="@+id/first_time_image"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scaleType="centerCrop"
        android:layout_below="@+id/swipe_refresh"
        android:background="@android:color/holo_green_dark"
        android:src="@drawable/drawable_image_tutorial_background"/>

</LinearLayout>


<com.shellanoo.newsbot.ui.views.GeneralErrorView
    android:id="@+id/no_data_errors_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:gev_no_data_view_layout="@layout/view_no_data_timeline"/>

<com.shellanoo.newsbot.ui.views.ProgressWheel
    android:id="@+id/loading_pb"
    style="@style/AppTheme.ProgressBar.Large"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:visibility="gone"/>

<ImageView
    android:id="@+id/my_topics_btn"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_gravity="bottom|left"
    android:paddingBottom="20dp"
    android:paddingLeft="24dp"
    android:paddingRight="30dp"
    android:paddingTop="20dp"
    android:visibility="gone"
    app:srcCompat="@drawable/profile_main"
    tools:visibility="visible"/>

<ImageView
    android:id="@+id/add_topics_btn"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_gravity="bottom|right"
    android:paddingBottom="20dp"
    android:paddingLeft="30dp"
    android:paddingRight="24dp"
    android:paddingTop="20dp"
    android:visibility="gone"
    app:srcCompat="@drawable/plus_main"
    tools:visibility="visible"/>

<com.shellanoo.newsbot.ui.views.NewStoriesIndicatorView
    android:id="@+id/new_items_tip"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:padding="8dp"
    app:layout_collapseMode="parallax"
    app:layout_collapseParallaxMultiplier="0.7"
    tools:text="5 new items"/>

</RelativeLayout>

有人知道为什么,以及如何解决这个问题吗?

【问题讨论】:

  • 分享你的xml代码可能是你在recyclerview中提供了match_parent属性,你必须限制recyclerview的高度,使用relativelayout/linearlayout作为父级
  • 你应该使用 RelativeLayout 作为父级,它更轻,它可能有助于解决你遇到的重叠问题,你能发布 xml 布局吗?
  • @SaravInfern 布局已添加。
  • 你已经在你的滑动刷新布局中添加了匹配父属性改变它
  • 将 swiperefreshlayout 高度更改为 wrap_content 不会改变行为。 ImageView 仍然不可见。

标签: android animation imageview off-screen


【解决方案1】:

这样试试

 <RelativeLayout
         android:id="@+id/layout"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content">
  <android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/swipe_refresh"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="200dp">


    <com.lsjwzh.widget.recyclerviewpager.RecyclerViewPager
        android:id="@+id/vertical_recycler_view"
        style="@style/NoOverScrollStyle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/white"
        app:rvp_singlePageFling="true"
        android:minHeight="200dp"/>   


    </android.support.v4.widget.SwipeRefreshLayout>

     <ImageView
         android:id="@+id/first_time_image"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:scaleType="centerCrop"
         android:layout_below="@+id/swipe_refresh"
         android:background="@android:color/holo_green_dark"
         android:src="@drawable/drawable_image_tutorial_background"/>
  </RelativeLayout>

【讨论】:

  • 尝试使用带有 SwipeRefreshLayout 和 wrap_content 高度的 RelativeLayout,但结果是相同的。图像不显示。
猜你喜欢
  • 2020-05-24
  • 2014-09-26
  • 2015-03-04
  • 1970-01-01
  • 1970-01-01
  • 2010-10-11
  • 1970-01-01
  • 2014-01-09
  • 2020-06-18
相关资源
最近更新 更多