Med*_*aly 129
您可以在要在前面看到的视图上调用bringToFront()
这是一个例子:
yourView.bringToFront();
Run Code Online (Sandbox Code Playgroud)
shr*_*wdu 36
我一直在寻找堆栈溢出来找到一个好的答案,当我找不到一个我去浏览文档.
似乎没有人偶然发现这个简单的答案:
ViewCompat.setTranslationZ(view, translationZ);
Run Code Online (Sandbox Code Playgroud)
默认翻译z是0.0
小智 21
更简单的解决方案是编辑活动的XML.使用
android:translationZ=""
Run Code Online (Sandbox Code Playgroud)
Jus*_*tin 19
bringToFront()是正确的方法,但是,请注意,您必须在最高级别视图(在根视图下)调用bringToFront()和invalidate()方法,例如:
您的视图的层次结构是:
-RelativeLayout
|--LinearLayout1
|------Button1
|------Button2
|------Button3
|--ImageView
|--LinearLayout2
|------Button4
|------Button5
|------Button6
Run Code Online (Sandbox Code Playgroud)
因此,当您为按钮设置动画(1-> 6)时,按钮将位于(下方)的下方ImageView.为了将它翻转(上图)ImageView,你必须调用bringToFront(),并invalidate()在你的方法LinearLayout秒.然后它将工作:)**注意:请记住设置android:clipChildren="false"您的根布局或动画视图的gradparent_layout.我们来看看我的真实代码:
.XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:hw="http://schemas.android.com/apk/res-auto"
android:id="@+id/layout_parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/common_theme_color"
android:orientation="vertical" >
<com.binh.helloworld.customviews.HWActionBar
android:id="@+id/action_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/dimen_actionbar_height"
android:layout_alignParentTop="true"
hw:titleText="@string/app_name" >
</com.binh.helloworld.customviews.HWActionBar>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/action_bar"
android:clipChildren="false" >
<LinearLayout
android:id="@+id/layout_top"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:gravity="center_horizontal"
android:orientation="horizontal" >
</LinearLayout>
<ImageView
android:id="@+id/imgv_main"
android:layout_width="@dimen/common_imgv_height"
android:layout_height="@dimen/common_imgv_height"
android:layout_centerInParent="true"
android:contentDescription="@string/app_name"
android:src="@drawable/ic_launcher" />
<LinearLayout
android:id="@+id/layout_bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center_horizontal"
android:orientation="horizontal" >
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
.java中的一些代码
private LinearLayout layoutTop, layoutBottom;
...
layoutTop = (LinearLayout) rootView.findViewById(R.id.layout_top);
layoutBottom = (LinearLayout) rootView.findViewById(R.id.layout_bottom);
...
//when animate back
//dragedView is my layoutTop's child view (i added programmatically) (like buttons in above example)
dragedView.setVisibility(View.GONE);
layoutTop.bringToFront();
layoutTop.invalidate();
dragedView.startAnimation(animation); // TranslateAnimation
dragedView.setVisibility(View.VISIBLE);
Run Code Online (Sandbox Code Playgroud)
格鲁克!
Ego*_*gor 15
试试吧FrameLayout,它让你可以把视图放在另一个上面.您可以创建两个LinearLayouts:一个具有背景视图,一个具有前景视图,并使用它们组合它们FrameLayout.希望这可以帮助.
Kri*_*hna 14
在xml中使用此代码
android:translationZ="90dp"
Run Code Online (Sandbox Code Playgroud)
我遇到了同样的问题。以下解决方案对我有用。
FrameLayout glFrame=(FrameLayout) findViewById(R.id.animatedView);
glFrame.addView(yourView);
glFrame.bringToFront();
glFrame.invalidate();
Run Code Online (Sandbox Code Playgroud)
第二种解决方案是使用 xml 将此属性添加到视图 xml
android:translationZ=""
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
165337 次 |
| 最近记录: |