日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

View 的 android:visibility属性的讨论

發(fā)布時間:2023/12/2 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 View 的 android:visibility属性的讨论 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

Android VIEW 中的?visibility?屬性,在API中的描述為:Controls the initial visibility of the view.?[控制VIEW的初始可見性]。

? 其中包含三個參數(shù):

? ?

? ?* 默認(rèn)值為visible,可見。這里需要注意的是 "invisible" 和 "gone" 的區(qū)別。API中的描述是:"invisible" :VIEW不顯示但是在布局中依然留有屬于它的位置。"gone" :不顯示,并且該VIEW不被添加。打個比方來說:某次會議中,A沒有來參加,但是A的位置依然留在那里,只是A不在而已。而“gone”則是指:A沒有參加會議,在安排的時候連A的位置都沒有安排。

? 下面看一個簡單的例子:

? 效果圖:?

????

代碼:

1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:tools="http://schemas.android.com/tools" 4 android:layout_width="match_parent" 5 android:layout_height="match_parent" 6 android:orientation="vertical" 7 tools:context="${relativePackage}.${activityClass}" > 8 9 <TextView 10 android:id="@+id/text1" 11 android:layout_width="fill_parent" 12 android:layout_height="wrap_content" 13 android:background="@color/red" 14 android:text="@string/view1" /> 15 16 <TextView 17 android:id="@+id/text2" 18 android:layout_width="fill_parent" 19 android:layout_height="wrap_content" 20 android:background="@color/green" 21 android:text="@string/view2" /> 22 23 <TextView 24 android:id="@+id/text3" 25 android:layout_width="fill_parent" 26 android:layout_height="wrap_content" 27 android:background="@color/blue" 28 android:text="@string/view3" /> 29 30 <LinearLayout 31 android:id="@+id/btns" 32 android:layout_width="fill_parent" 33 android:layout_height="wrap_content" 34 android:orientation="horizontal" > 35 36 <Button 37 android:id="@+id/btn_visible" 38 android:layout_width="wrap_content" 39 android:layout_height="wrap_content" 40 android:onClick="setVisible" 41 android:text="@string/btn1" /> 42 43 <Button 44 android:id="@+id/btn_invisible" 45 android:layout_width="wrap_content" 46 android:layout_height="wrap_content" 47 android:onClick="setInvisible" 48 android:text="@string/btn2" /> 49 50 <Button 51 android:id="@+id/btn_gone" 52 android:layout_width="wrap_content" 53 android:layout_height="wrap_content" 54 android:onClick="setGone" 55 android:text="@string/btn3" /> 56 </LinearLayout> 57 58 </LinearLayout> main_layout 1 <?xml version="1.0" encoding="utf-8"?> 2 <resources> 3 <color name="red">#FF0000</color> 4 <color name="green">#00FF00</color> 5 <color name="blue">#0000FF</color> 6 </resources> 7 8 9 <?xml version="1.0" encoding="utf-8"?> 10 <resources> 11 12 <string name="app_name">VisiblityApp</string> 13 <string name="view1">View1</string> 14 <string name="view2">View2</string> 15 <string name="view3">View3</string> 16 <string name="btn1">Visible</string> 17 <string name="btn2">Invisible</string> 18 <string name="btn3">Gone</string> 19 20 </resources> color.xml string.xml 1 public class MainActivity extends Activity { 2 private TextView textView2; 3 4 @Override 5 protected void onCreate(Bundle savedInstanceState) { 6 super.onCreate(savedInstanceState); 7 setContentView(R.layout.activity_main); 8 textView2 = (TextView) findViewById(R.id.text2); 9 } 10 11 public void setVisible(View v) { 12 textView2.setVisibility(View.VISIBLE); 13 } 14 15 public void setInvisible(View v) { 16 textView2.setVisibility(View.INVISIBLE); 17 } 18 19 public void setGone(View v) { 20 textView2.setVisibility(View.GONE); 21 } 22 23 } MainActivity?

?

* 到此結(jié)束。

番外篇: 回想一下自己離開J2EE也已經(jīng)兩年了,這兩年經(jīng)歷了很多很多,這兩年也看透很多。也許這一切都是我咎由自取… 呵呵,日子還是要繼續(xù),一步一步的走吧。以后的日子里,每天都會寫一篇,來記錄Android學(xué)習(xí)的路。

轉(zhuǎn)載于:https://www.cnblogs.com/antroy/p/4182631.html

創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎

總結(jié)

以上是生活随笔為你收集整理的View 的 android:visibility属性的讨论的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。