Era*_*ray 61 java animation android android-animation
我在这个LinearLayout中有一个LinearLayout和ImageView.
ImageView有一个翻译效果.
// v = ImageView
ObjectAnimator animation2 = ObjectAnimator.ofFloat(v, "translationY", 200);
animation2.setDuration(3000);
animation2.setTarget(v);
animation2.start();
Run Code Online (Sandbox Code Playgroud)
动画工作但是当ImageView超出LinearLayout时它就消失了.
你可以在这里看到问题:http://screenr.com/zoAH
如何在不修改LinearLayout高度的情况下修复它.
小智 80
找到ImageView所属的ViewGroup并应用ViewGroup.setClipChildren(false).默认情况下,子项的绘制仅限于父ViewGroup的边界.
Max*_*ell 75
存在两个可能导致此情况发生的属性:clipChildren和clipToPadding.对于每个父ViewGroup,您需要将clipChildren设置为false,该ViewGroup将对象进行动画处理.您还需要将clipToPadding设置为直接父级(可能更多,但我还没有看到它的情况).
您可以在XML中设置这两个属性
android:clipChildren="false"
android:clipToPadding="false"
Run Code Online (Sandbox Code Playgroud)
或者在代码中
viewGroup.setClipChildren(false);
viewGroup.setClipToPadding(false);
Run Code Online (Sandbox Code Playgroud)
ahm*_*_89 16
我的实施.它可能可以帮助某人:
Java版本:
public static void setAllParentsClip(View v, boolean enabled) {
while (v.getParent() != null && v.getParent() instanceof ViewGroup) {
ViewGroup viewGroup = (ViewGroup) v.getParent();
viewGroup.setClipChildren(enabled);
viewGroup.setClipToPadding(enabled);
v = viewGroup;
}
}
Run Code Online (Sandbox Code Playgroud)
调用
setAllParentsClip(yourView, false);
以禁用所有父项中的剪辑.
编辑:
Kotlin的版本作为扩展功能:
fun View.setAllParentsClip(enabled: Boolean) {
var parent = parent
while (parent is ViewGroup) {
parent.clipChildren = enabled
parent.clipToPadding = enabled
parent = parent.parent
}
}
Run Code Online (Sandbox Code Playgroud)
呼叫: yourView.setAllParentsClip(false)
归档时间: |
|
查看次数: |
32599 次 |
最近记录: |