开发者社区 问答 正文

view问题

https://docs.alipay.com/mini/component/view
view的常见问题是什么意思?看完之后还是不知道怎么改 view 的展示顺序

展开
收起
游客clfty74mzp7oi 2019-10-29 17:12:16 569 分享
分享
版权
举报
1 条回答
写回答
取消 提交回答
  • 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

    <Button  
        android:id="@+id/textviewId"  
        android:layout_width="match_parent"  
        android:layout_height="wrap_content"  
        android:text="@string/hello_world" />  
    


    ng/article/details/40450753

    2019-10-29 19:05:12 举报
    赞同 评论

    评论

    全部评论 (0)

    登录后可评论
问答地址: