android如何修改view的显示前后位置。
来源:互联网 发布:淘宝消息管理器在哪里 编辑:程序博客网 时间:2024/04/29 12:39
此方法源自:http://blog.csdn.net/goodlixueyong/article/details/40425387
如果父控件是frameLayout那么后加上的控件就要在最上层显示了。如果动态修改那个控件显示在最上层。
下面看效果图,
下面是两个按钮,第一个可以按到hello lyf按钮,第二个按不到hello lyf按钮,下面看是如何实现让hello lyf到z轴最前面的。
代码:
MainActivity.java
package com.example.bringtofrontdemo;import android.app.Activity;import android.os.Bundle;import android.widget.Button;import android.widget.FrameLayout;public class MainActivity extends Activity {private Button button;private FrameLayout rootFrameLayout; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); button=(Button)findViewById(R.id.textviewId); Button secondButton=new Button(this); rootFrameLayout=(FrameLayout)findViewById(R.id.root); secondButton.setWidth(100); secondButton.setHeight(50); secondButton.setText("签名阿德。"); rootFrameLayout.addView(secondButton); //这样原先的那个button就会到了最前面。 button.bringToFront(); //android4.4之前的版本需要让view的父控件调用这两个方法使其重绘。 rootFrameLayout.requestLayout(); rootFrameLayout.invalidate(); }}
activity_main.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/root" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" > <Button android:id="@+id/textviewId" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/hello_world" /></FrameLayout>
0 0
- android如何修改view的显示前后位置。
- Android中修改toast的显示位置
- 修改 android Dialog 对话框显示的位置
- Context-Menu.Android库的使用(修改显示位置)
- Android自定义View之IndicatorView,显示当前tab页所处位置的View
- Android View的位置参数
- [Android]:View的位置参数
- Android View的一些位置
- Android View的位置参数
- android studio如何修改默认的sdk的位置。、
- Android 指定Toast信息显示的位置并使用Toast显示其他View
- Android自定义Toast,指定Toast信息显示的位置并使用Toast显示其他View
- Android 获取view的位置和设置view的位置
- Android系统修改导航栏显示位置
- Android RelativeLayout动态修改子控件位置(可连续拖动的View)
- Android自定义Toast的时长、位置、及显示的View
- ldd 显示的so的位置修改
- 修改 EditText 中的光标显示的位置
- PHP date时间处理
- PE地址名词总结及基本概念
- swift中 tableviewcontroler控件 关于固定tableview下的某个控件
- Android5.0之RecyclerView、CardView、Palette简述(后面逐步发详细的)
- protobuf 一个.proto 文件的简单讲解
- android如何修改view的显示前后位置。
- 剑指offer面试题8--数组旋转
- IOS突破限制--3
- Week Plan: 2014.10.25-2014.10.31
- ReentrantLock解析
- emacs java mode
- 152_leetcode_Find Minimum in Rotated Sorted Array
- 解决root用户登录Ubuntu14.04 图形界面
- 12种不宜使用的Javascript语法