相关疑难解决方法(0)

自定义android AccelerateDecelerateInterpolator

我正在尝试使用AccelerateDecelerateInterpolator并自定义它.我可以看到像DecelerateInterpolator这样的插值器有一个"因子"字段,所以你可以改变它的行为.但AccelerateDecelerateInterpolator没有.当我使用AccelerateDecelerateInterpolator时,我几乎甚至都注意到内插器正在做任何事情.动画看起来非常线性.那么,有没有办法考虑AccelerateDecelerateInterpolator或以任何方式改变它?谢谢

animation android interpolation

11
推荐指数
1
解决办法
6595
查看次数

即使在从GONE变为VISIBLE之前,也可以准确地确定视图的测量高度

目前,我的布局看起来像这样.它包含.

  • 标题文本视图和价格文本视图,始终可见.
  • 说明文本视图,可以显示或消失,具体取决于展开或折叠.

折叠(在应用启动期间)

在此输入图像描述

扩展(当用户点击它时)

在此输入图像描述

我希望周围有一些不错的动画.所以,我提到了/sf/answers/936685991/

其中一个关键因素是,即使在可见之前,也要知道描述文本视图的确切高度.

但是,我意识到了一些类型的代码.他们不准确

// v is description text view.
v.measure(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
final int targtetHeight = v.getMeasuredHeight();
Run Code Online (Sandbox Code Playgroud)
// v is description text view.
v.measure(MeasureSpec.makeMeasureSpec(LayoutParams.MATCH_PARENT, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(LayoutParams.WRAP_CONTENT, MeasureSpec.EXACTLY));
final int targtetHeight = v.getMeasuredHeight();
Run Code Online (Sandbox Code Playgroud)

这将返回值32.(正确的测量高度假设为92).这是第一行文本的高度.这最终我的动画结束了

在此输入图像描述

我是否知道,确定视图的测量高度的正确方法是什么,甚至在它从GONE变为VISIBLE之前?

我的布局代码如下:

        <LinearLayout
            android:clickable="true"
            android:id="@+id/chart_linear_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:background="@drawable/dummy"
            android:orientation="vertical">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="10dp"
                android:orientation="horizontal">
                <TextView
                    android:layout_width="0dp"
                    android:width="0dp"
                    android:layout_weight="0.6"
                    android:layout_height="match_parent"
                    android:gravity="left"
                    android:textSize="20sp" 
                    android:textColor="#ff000000"
                    android:text="Summary chart" />
                <TextView
                    android:id="@+id/chart_price_text_view"
                    android:layout_width="0dp"
                    android:width="0dp"
                    android:layout_weight="0.4"
                    android:layout_height="match_parent"
                    android:gravity="right"
                    android:textSize="20sp" 
                    android:textColor="#ffF76D3C"
                    android:text="$2.99" /> …
Run Code Online (Sandbox Code Playgroud)

android

11
推荐指数
1
解决办法
2万
查看次数

展开/折叠动画:小滞后|| MeasureSpec返回错误的值

我用的是下面两种方法(启发/从这里复制)到expandcollapse一些TextViewsScrollView通过点击"头" - TextView.

伪布局结构:

<ScrollView>
    <LinearLayout>
        <LinearLayout>
            <!-- some other stuff here -->
        </LinearLayout>
        <TextView "header1"/>
        <View "fancydivider"/>
        <TextView "content1">
        <TextView "header2"/>
        <View "fancydivider"/>
        <TextView "content2">
    </LinearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)

分频器很简单View,height设置为1dp.内容TextViews风格包括:

    <item name="android:layout_height">0dp</item>
    <item name="android:layout_width">match_parent</item>
Run Code Online (Sandbox Code Playgroud)

和一些边距和填充.

方法在这里:

public static void expand(final View v) {

    //v.measure(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);

    int matchParentMeasureSpec = View.MeasureSpec.makeMeasureSpec(((View) v.getParent()).getWidth(), View.MeasureSpec.EXACTLY);
    int wrapContentMeasureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    v.measure(matchParentMeasureSpec, wrapContentMeasureSpec);

    final int targetHeight = …
Run Code Online (Sandbox Code Playgroud)

android android-animation

10
推荐指数
1
解决办法
582
查看次数

如何在android中制作可扩展的面板布局?

我在android中做了非常复杂的布局?

我需要两个面板,如果一个扩展另一个扩展,否则,我想做一个像吸水器的行为,但因为我只能在视图中按钮,没有别的我有深陷困境.

在此输入图像描述

这里是我需要帮助的例子,我已经花了3天时间,没有找到答案.

这是我的代码

    <RelativeLayout android:id="@+id/imagesContent" android:orientation="vertical" android:layout_alignBottom="@+id/lhsLogo"
                    android:layout_width="wrap_content" android:layout_height="wrap_content">
        <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="3dp"
                   android:src="@drawable/orange_price_tag" android:layout_toLeftOf="@+id/lhsLogo" android:layout_alignBottom="@+id/lhsLogo" />
        <LinearLayout android:layout_centerHorizontal="true" android:orientation="vertical" android:layout_width="wrap_content"
                      android:layout_height="wrap_content">
            <TextView android:layout_width="fill_parent" android:layout_height="0dp" android:text="50%" android:singleLine="false"
                      android:textColor="#ffffff" android:textSize="17dp" android:id="@+id/discountTypeNumbers" android:layout_weight="1" />
            <TextView android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="????" android:singleLine="false"
                      android:textColor="#ffffff" android:textSize="14dp" android:id="@+id/discountTypeText" />
        </LinearLayout>
    </RelativeLayout>

    <TextView android:id="@+id/detailsTextContent"
              android:layout_below="@+id/imagesContent"
              android:layout_width="fill_parent"
              android:layout_height="200dp"
              android:textSize="11dp"
              android:layout_marginLeft="10dp"
              android:layout_marginRight="10dp"
              android:scrollbars = "vertical"
              android:layout_marginTop="10dp"
              android:text="some textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome textsome …
Run Code Online (Sandbox Code Playgroud)

android android-layout

9
推荐指数
1
解决办法
3万
查看次数

Android:使用展开动画添加视图(不闪烁)

我想使用扩展动画向视图组添加视图,因此添加的视图开始非常小并占用越来越多的空间,直到达到其完整大小(可能在此过程中移动其他视图).

在尝试不同的方法后,我想出了下面的解决方案.投票,如果它可以帮助您或请发布更好的替代品.我相信必须有一个更简单的方法来做到这一点.

有关更多信息,请参阅此类此类的帖子.

这是我添加视图并启动动画的方法:

// Trick: set height to 1 so the view doesn't take its full size at the beginning.
// (0 doesn't work, I don't know why)
container.addView(view, LayoutParams.MATCH_PARENT, 1);
Animation expansion = createExpansion(view);
expansion.setDuration(200);
view.startAnimation(expansion);
Run Code Online (Sandbox Code Playgroud)

createExpansion()方法:

public static Animation createExpansion(View view) {

    return new SizedHeightScaleAnimation(view, 0, 1,
            Animation.RELATIVE_TO_SELF, 0f,
            Animation.RELATIVE_TO_SELF, 0f);
}
Run Code Online (Sandbox Code Playgroud)

最后是SizedHeightScaleAnimation动画类:

/**
 * Like {@link ScaleAnimation} for height scaling that also resizes the view accordingly,
 * so …
Run Code Online (Sandbox Code Playgroud)

layout animation android

9
推荐指数
1
解决办法
1万
查看次数

编舞者NullPointerException

我一直在研究现有的代码库并且浏览我们的崩溃日志服务我注意到异常发生的频率非常频繁,我无法重现这个问题,我也没有为方案尝试上下文因为这是一个非常大的项目,所以越来越难以找出这个例外的原因.

我一直在网上搜索类似的问题,但找不到任何有用的信息.如果有人熟悉这个问题,我们将非常感谢您的帮助.

Stacktrace如下:

java.lang.NullPointerException
   at android.animation.PropertyValuesHolder.setupSetterAndGetter(PropertyValuesHolder.java:505)
   at android.animation.ObjectAnimator.initAnimation(ObjectAnimator.java:487)
   at android.animation.ValueAnimator.setCurrentPlayTime(ValueAnimator.java:517)
   at android.animation.ValueAnimator.start(ValueAnimator.java:936)
   at android.animation.ValueAnimator.start(ValueAnimator.java:946)
   at android.animation.ObjectAnimator.start(ObjectAnimator.java:465)
   at android.animation.AnimatorSet$1.onAnimationEnd(AnimatorSet.java:579)
   at android.animation.ValueAnimator.endAnimation(ValueAnimator.java:1056)
   at android.animation.ValueAnimator.access$400(ValueAnimator.java:50)
   at android.animation.ValueAnimator$AnimationHandler.doAnimationFrame(ValueAnimator.java:644)
   at android.animation.ValueAnimator$AnimationHandler.run(ValueAnimator.java:660)
   at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
   at android.view.Choreographer.doCallbacks(Choreographer.java:574)
   at android.view.Choreographer.doFrame(Choreographer.java:543)
   at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
   at android.os.Handler.handleCallback(Handler.java:733)
   at android.os.Handler.dispatchMessage(Handler.java:95)
   at android.os.Looper.loop(Looper.java:136)
   at android.app.ActivityThread.main(ActivityThread.java:5105)
   at java.lang.reflect.Method.invokeNative(Method.java)
   at java.lang.reflect.Method.invoke(Method.java:515)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608)
   at dalvik.system.NativeStart.main(NativeStart.java)
Run Code Online (Sandbox Code Playgroud)

干杯.

android nullpointerexception

9
推荐指数
2
解决办法
3818
查看次数

如何缩放View/ViewGroup - 以适当的方式设置动画布局?

简而言之,我想缩放视图 - 就像Android Market一样,当你单击"更多"按钮时,在例如'描述'上.
我弄清楚,Android Market具有以下结构的布局:

    <FrameLayout
    android:id="@+id/artists_frame"
    android:layout_width="fill_parent"
    android:layout_height="64dip"
    android:layout_below="@id/something1"
    android:layout_above="@id/something2"

    >

<!-- Some view there, which height >> 64dip -->

    </FrameLayout>
Run Code Online (Sandbox Code Playgroud)

所以,我在FrameLayout(via view.setAnimation(), view.setLayoutAnimation()ScaleAnimation)上尝试了各种动画/ LayoutAnimations ,但效果总是一样的:视图动画,但是缩放后的真实layout_height仍然是相同的(所以其他视图的位置,那个取决于给定的FrameLayout,保持不变).

之后,我想 - 我在循环中更改了给定FrameLayout的layout_height:

layoutParams = view.getLayoutParams()
layoutParams.height = scaleTo;
layout.setLayoutParams(layoutParams);
Run Code Online (Sandbox Code Playgroud)

我有它的动画,市场般的观点,但成本(性能!!!)是高...

因此,问题是:是否有任何其他适当的方法来缩放(例如将高度从50dip更改为200dip)给定的View/ViewGroup,以便动画视图下方的视图位置也发生变化?

animation android android-layout layout-animation

7
推荐指数
1
解决办法
5479
查看次数

扩展recyclerview项目

如果我展开recyclerview中的任何项目它扩展正常,但当我向下滚动recylerview我发现其他项目也扩大,由于回收它采取扩大的尺寸而不是原来的

 public class FeedAdapter extends RecyclerView.Adapter<FeedAdapter.MyViewHolder> implements View.OnClickListener {

    private LayoutInflater inflater;
    private Context mcontext;
    private int mOriginalHeight = 0;
    private boolean mIsViewExpanded = false;

    public FeedAdapter(Context context) {
        inflater = LayoutInflater.from(context);
        mcontext = context;

    }


    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {

        View view = inflater.inflate(R.layout.custom_row, viewGroup, false);
        MyViewHolder holder = new MyViewHolder(view);
        holder.frame.setOnClickListener(this);


        return holder;
    }

    @Override
    public void onBindViewHolder(MyViewHolder myViewHolder, int i) {


    }

    @Override
    public int getItemCount() {
        return 100;
    }

    @Override
    public void onClick(final …
Run Code Online (Sandbox Code Playgroud)

android android-animation android-recyclerview

7
推荐指数
1
解决办法
9828
查看次数

Android:上/下动画滑动菜单

我尝试了几种解决方案,但需要帮助。以下主题非常有用,但我认为我做错了。如何设置两者的布局高度/设置?假设我有2个LinearLayout用于内容和底部菜单。

我也不希望底部菜单在滑动后消失。它应该在那里恒定。我正在为菜单单击/更改视图使用片段。

Android:展开/折叠动画

Android动画下拉/上视图正确

在此处输入图片说明

animation android menu view sliding

5
推荐指数
1
解决办法
1万
查看次数

Android展开/折叠RelativeLayout

我从该主题尝试了各种解决方案(请参阅Android:展开/折叠动画),但没有一个真正适合我。我确信投票最多的人是好人,而它行不通的原因是我听不懂。请告诉我我在做什么错。先感谢您 :)

编辑:我的问题的重点是,当我单击元素'relativeZaplon'时,它可以很好地扩展,但是当我要折叠它时,它并不对应。

主要活动

 public class MainActivity extends AppCompatActivity {

    private boolean isVisible = false;
    private RelativeLayout mRelativeZaplon;
    private RelativeLayout mRelativeToSlide;
    private ExpandOrCollapse mAnimationManager;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mAnimationManager = new ExpandOrCollapse();
        mRelativeZaplon = (RelativeLayout) findViewById(R.id.relativeZaplon);
        mRelativeToSlide = (RelativeLayout) findViewById(R.id.relativevToSlide);
        mRelativeZaplon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (isVisible) {
                    mAnimationManager.collapse(mRelativeToSlide, 1000, 200);
                    isVisible = false;
                } else if (!isVisible){
                    mAnimationManager.expand(mRelativeToSlide, 1000, 200);
                    isVisible = true;
                }
            }
        });
    }
} …
Run Code Online (Sandbox Code Playgroud)

layout android collapse android-animation

5
推荐指数
2
解决办法
7562
查看次数

如何像通知中那样展开和折叠 RecyclerView 中的项目

在此输入图像描述

我想在 RecyclerView 中实现展开和折叠,如 gif 中所述。通过粘贴并上下滑动。我在下面尝试过, /sf/answers/936685991/ 很好,但不是我所期望的。 我使用 RecyclerView 列出应用程序内的所有通知。如果有人有任何想法或经验,请与我分享。任何帮助将不胜感激。提前致谢。

在大多数网站中,能够找到实现左右滑动的方法,但不能实现上下滑动。我想实现向上和向下滑动,就像向左滑动和向右滑动一样。 在 gif 中,我没有使用箭头来展开和折叠,我只是上下滑动。我想在应用程序内的 recyclerview 中实现同样的目标。

java android android-recyclerview

4
推荐指数
1
解决办法
2058
查看次数

如何动画列表视图展开和折叠

最初在屏幕底部显示文本.单击它时,它下面的列表视图应该向上滑动.再次单击文本,列表视图向下滑动.

使其与下面的代码段一起使用,除了第一次单击文本列表不会使动画向上滑动.之后,它将按预期动画上下滑动.

这是因为在第一次点击并调用showListView(true); 由于列表视图的可见性"已消失",因此它没有高度."y"== 0翻译没有做任何事情.它只是将列表视图的可见性更改为"可见",这会推动titleRow更改其位置.

但是如果要从列表视图的可见性开始"可见",则初始showListView(false); 在setupListViewAdapter()中没有将列表视图向下推到初始状态(屏幕底部之外),因为它没有高度,直到列表行由mListView.setAdapter(mListAdapter)从适配器填充.

是否有更好的方法来进行列表视图的上下移动?

        <TextView
                android:id="@+id/titleRow”
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text=“title row”
        />

        <ListView
            android:id="@+id/list_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:visibility=“gone”
            >
        </ListView>


initial state list view collapsed(outside screen bottom)
+++++++++++++++++++++++++++
+  mTitleRow          + ^ +
+++++ screen bottom   +++++


listview expanded
+++++++++++++++++++++++++++
+  mTitleRow          + ^ +
+++++++++++++++++++++++++++
+                         +
+  mListView              +
+                         +
+++++ screen bottom   +++++


void setupListViewAdapter(){
        mTitleRow.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mTitleRow.getTag() == STATE_COLLAPSED)                    
                { 
                   mListView.setVisibility(View.VISIBLE);                       
                   showListView(true);
                } else { …
Run Code Online (Sandbox Code Playgroud)

animation android listview

2
推荐指数
1
解决办法
3117
查看次数

android-CardView在RecyclerView中调整动画大小

我有一个CardCard作为其中的RecyclerView项目。CardView具有箭头图标以在同一CardView中显示详细信息,但我不想将其设置为GONE或VISIBLE,因为此操作没有美观的动画。我试图android:animateLayoutChanges="true"在CardView上进行设置,但得到了以下信息:(这不是我的屏幕,但包含相同的问题)

在此处输入图片说明

但是,一旦我再次单击箭头以折叠辅助文字,下面的卡片就会与我在动画过程中单击的卡片重叠。如何避免这种重叠?我试图打电话给我,TransitionManager.beginDelayedTransition(CardView);但看起来对我没有帮助。

animation android android-recyclerview cardview

1
推荐指数
1
解决办法
1156
查看次数