美文网首页
安卓 简单的遮罩层

安卓 简单的遮罩层

作者: Pino | 来源:发表于2019-03-07 11:23 被阅读0次
    <?xml version="1.0" encoding="utf-8"?>  
            <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"  
                android:id="@+id/layout"  
                android:layout_width="fill_parent"  
                android:layout_height="fill_parent"   
                android:background="#fff">  
                <RelativeLayout  
                    android:layout_width="fill_parent"  
                    android:layout_height="wrap_content"  
                    android:layout_gravity="bottom"  
                    android:background="#86222222"  
                    android:orientation="horizontal" >  
              
                    <TextView  
                        android:id="@+id/titleTextView"  
                        android:layout_width="wrap_content"  
                        android:layout_height="wrap_content"  
                        android:text="遮罩效果"  
                        android:textColor="#ff0000" />  
              
                    <Button  
                        android:id="@+id/unfoldButton"  
                        android:layout_width="wrap_content"  
                        android:layout_height="wrap_content"  
                        android:layout_alignParentRight="true"  
                        android:text="显示遮罩" />  
                </RelativeLayout>  
              
            </FrameLayout> 
    
    
    public class ShadeActivity extends Activity {  
            // 设置是否展开  
            private boolean isFolded = true;  
            // 设置控件  
            private FrameLayout layout = null;  
            private Button unfoldButton = null;  
            private TextView textView = null;  
          
            public void onCreate(Bundle savedInstanceState) {  
                super.onCreate(savedInstanceState);  
                requestWindowFeature(Window.FEATURE_NO_TITLE);  
                setContentView(R.layout.activity_shade);  
          
                initView();  
            }  
          
            @Override  
            protected void onResume() {  
                // TODO Auto-generated method stu  
                super.onResume();  
                isFolded = true;  
            }  
          
            // 初始化  
            private void initView() {  
                layout = (FrameLayout) findViewById(R.id.layout);  
                unfoldButton = (Button) findViewById(R.id.unfoldButton);  
                unfoldButton.setOnClickListener(new UnfoldClickListener());  
            }  
          
            // 按钮监听,展开一个透明的显示文本的遮挡层  
            private class UnfoldClickListener implements OnClickListener {  
                public void onClick(View v) {  
                    if (isFolded) {  
                        textView = new TextView(ShadeActivity.this);  
                        textView.setTextColor(Color.BLUE);  
                        textView.setTextSize(20);  
                        textView.setText("滚滚长江东逝水,浪花淘尽英雄。\n" + "是非成败转头空,\n"  
                                + "青山依旧在,几度夕阳红。\n" + "白发渔樵江渚上,惯看秋月春风。 \n"  
                                + "一壶浊酒喜相逢,\n" + "古今多少事,都付笑谈中。");  
                        textView.setGravity(Gravity.CENTER);  
                        textView.setLayoutParams(new ViewGroup.LayoutParams(  
                                ViewGroup.LayoutParams.FILL_PARENT,  
                                ViewGroup.LayoutParams.FILL_PARENT));  
                        textView.setBackgroundColor(Color.parseColor("#86222222"));  
          
                        unfoldButton.setText("取消遮罩");  
          
                        isFolded = false;  
          
                        layout.addView(textView);  
                    } else {  
                        unfoldButton.setText("显示遮罩");  
                        isFolded = true;  
                        layout.removeView(textView);  
                    }  
                }  
            }  
        }
    
    

    相关文章

      网友评论

          本文标题:安卓 简单的遮罩层

          本文链接:https://www.haomeiwen.com/subject/zntcpqtx.html