Android中visibility属性GONE、VISIBLE、INVISIBLE、

The difference between the visibility attributes VISIBLE, INVISIBLE, and GONE in Android! ! ! !

Visible

XML file: android: visibility = "visible"

Java代码:view.setVisibility(View.VISIBLE);

Invisible

XML file: android: visibility = "invisible"

Java代码:view.setVisibility(View.INVISIBLE);

Hide (GONE)

XML file: android: visibility = "gone"

Java code: view.setVisibility (View.GONE);

VISIBLE: Set control visible
INVISIBLE: Set control invisible
GONE: Set control hidden

//事件实现,日期设置是关闭状态,当你点击按钮的时候显示日期
   <Button 
        android:id="@+id/btn1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="选择日期"
        />
    
    <!-- android:visibility="gone"设置日期隐藏属性 -->
    <DatePicker
         android:id="@+id/dpPicker"
         android:calendarViewShown="false"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
		//隐藏属性
         android:visibility="gone"
          />
  @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btn1 = (Button) findViewById(R.id.btn1);
        //设置点击事件,点击的时候让他显示出来
        btn1.setOnClickListener(this);
    }


	@Override
	public void onClick(View v) {
		//找到控件
		dpPicker = (DatePicker) findViewById(R.id.dpPicker);
		//visible显示属性
		dpPicker.setVisibility(View.VISIBLE);
	}

The main differences between INVISIBLE and GONE are:

When the visibility property of the control is INVISIBLE, the interface reserves the space occupied by the view control;

When the control property is GONE, the interface does not retain the space occupied by the view control.

Thank you for your support, if you want to understand the software industry, let's work hard together, and strive to add wei: zzaizhangzeng

Published 23 original articles · Like 11 · Visits 30,000+

Guess you like

Origin blog.csdn.net/weixin_42279584/article/details/88812449