ÉèΪÊ×Ò³ ¼ÓÈëÊÕ²Ø

TOP

Android¿ª·¢£ºLayout³£Óü¼ÇÉ(Ò»)
2014-11-24 11:36:39 À´Ô´: ×÷Õß: ¡¾´ó ÖРС¡¿ ä¯ÀÀ:2´Î
Tags£ºAndroid ¿ª·¢ Layout ³£Óà ¼¼ÇÉ

ÎÒÃǾ­³£Óõ½µÄ¿Ø¼þ¶¼ÊÇ View µÄÅÉÉúÀ࣬ËûÃÇͨ³£¶¼ÊǿɼûµÄ¡£ ViewGroup Ò²ÊÇ View µÄÅÉÉúÀ࣬µ« ViewGroup ͨ³£ÊDz»¿É¼ûµÄ¡£


ViewGroup µÄÖ÷Òª×÷Óãº


+ ×÷Ϊ Layout ¡£±ÈÈç LinearLayout ¡¢ RelativeLayout ¡¢ FrameLayout ºÍ TableLayout


+ ×÷Ϊ View µÄÈÝÆ÷¡£±ÈÈç Gallery ¡¢ GridView ¡¢ ImageSwitcher ¡¢ ScrollView ¡¢ TabHost ºÍ ListView


Æäʵ Layout Ò²¿ÉÒÔ±»ÈÏΪÊÇ View µÄÒ»ÖÖÈÝÆ÷¡£


±¾ÎĽöÌÖÂÛ ViewGroup ×÷Ϊ Layout µÄ³£Óü¼ÇÉ¡£


1. LinearLayout


LinearLayout ¹ËÃû˼Òå¾ÍÊÇÏßÐÔ²¼¾Ö¡£Æä×Ó View ¶ÔÏóҪôÒÔ ¡° ÐÐ ¡± ÅÅÁУ¬ÒªÃ´ÒÔ ¡° ÁÐ ¡± ÅÅÁУ¬ÕâÈ¡¾öÓÚÆä orientation ÊôÐÔÊÇ horizontal »¹ÊÇ vertical µÄ¡£


< xml version = "1.0" encoding = "utf-8" >


< LinearLayout


xmlns:android = "http://schemas.android.com/apk/res/android"


android:orientation = "vertical"


android:layout_width = "wrap_content"


android:layout_height = "wrap_content" >



< Button


android:id = "@+id/linearbutton01"


android:layout_width = "wrap_content"


android:layout_height = "wrap_content"


android:text = " °´Å¥ 1"


/>



< Button


android:id = "@+id/linearbutton02"


android:layout_width = "wrap_content"


android:layout_height = "wrap_content"


android:text = " °´Å¥ 2"


/>



< Button


android:id = "@+id/linearbutton01"


android:layout_width = "wrap_content"


android:layout_height = "wrap_content"


android:text = " °´Å¥ 3"


/>



< Button


android:id = "@+id/linearbutton01"


android:layout_width = "wrap_content"


android:layout_height = "wrap_content"


android:text = " °´Å¥ 4"


/>


LinearLayout >



½« Activity ¶ÔÓ¦µÄ´úÂëÖÐµÄ setContentView µÄ²ÎÊý£¬¸ÄΪ£º R.layout.linearlayout £¬ÔËÐкóµÃµ½µÄ½á¹ûÈçÏ£º





Èç¹û½« linearlayout.xml ÖÐµÄ orientation ÊôÐÔÖµ¸ÄΪ ¡±horizontal¡± £¬ÄÇôÔËÐкóµÄ½á¹ûÈçÏ£º





2. RelativeLayout


RelativeLayout ¿ÉÒÔ¸ù¾Ý×Ó View ¶ÔÏó±Ë´ËÖ®¼äµÄλÖùØÏµÀ´ÏÔʾ×Ó View ¶ÔÏó¡£±ÈÈçͨ¹ý ¡±above¡± ¡¢ ¡±below¡± ¡¢ ¡±to the left of¡± ¡¢ ¡±to the right of¡± ÆäËûµÄ×Ó View ¶ÔÏóÀ´¶¨Î»¡£



´´½¨Ò»¸ö²¼¾ÖÎļþ relativelayout.xml £¬Ê¹ÆäÄÚÈÝÈçÏ£º


< xml version = "1.0" encoding = "utf-8" >


< RelativeLayout


xmlns:android = "http://schemas.android.com/apk/res/android"


android:id = "@+id/relativelayout"


android:layout_width = "fill_parent"


android:layout_height = "fill_parent" >



< Button


android:id = "@+id/buttonCenter"


android:layout_width = "wrap_content"


android:layout_height = "wrap_content"


android:text = "Center"


android:layout_centerInParent = "true"


/>



< ImageView


android:id = "@+id/ImageView01"


android:layout_width = "wrap_content"


android:layout_height = "wrap_content"


android:layout_above = "@id/buttonCenter"


android:layout_centerHorizontal = "true"


android:src = "@drawable/icon"


/>



< TextView


android:id = "@+id/textview01"


android:layout_width = "wrap_content"


android:layout_height = "wrap_content"


android:layout_toLeftOf = "@id/buttonCenter"


android:textSize = "20px"


android:text = "Android1"


/>



< TextView


android:id = "@+id/textview02"


andro

Ê×Ò³ ÉÏÒ»Ò³ 1 2 ÏÂÒ»Ò³ βҳ 1/2/2
¡¾´ó ÖРС¡¿¡¾´òÓ¡¡¿ ¡¾·±Ìå¡¿¡¾Í¶¸å¡¿¡¾Êղء¿ ¡¾ÍƼö¡¿¡¾¾Ù±¨¡¿¡¾ÆÀÂÛ¡¿ ¡¾¹Ø±Õ¡¿ ¡¾·µ»Ø¶¥²¿¡¿
·ÖÏíµ½: 
ÉÏһƪ£ºAndroid¿ª·¢£ºGridView³£Óü¼ÇÉ ÏÂһƪ£ºAndroid¿ª·¢£ºTheme³£Óü¼ÇÉ

ÆÀÂÛ

ÕÊ¡¡¡¡ºÅ: ÃÜÂë: (ÐÂÓû§×¢²á)
Ñé Ö¤ Âë:
±í¡¡¡¡Çé:
ÄÚ¡¡¡¡ÈÝ:

¡¤Spring Boot Java£º (2025-12-26 16:20:19)
¡¤Spring Boot¤ÇHello (2025-12-26 16:20:15)
¡¤Spring ¤Î»ù±¾¤«¤éŒ (2025-12-26 16:20:12)
¡¤C++Ä£°å (template) (2025-12-26 15:49:49)
¡¤C ÓïÑÔÖÐÄ£°åµÄ¼¸ÖÖ (2025-12-26 15:49:47)