【】刚接触android,遇到xml里的android:layout_width和android:width,觉得他们类似,但是有说不出有什么区别,google后觉得说的都不太明白,遂自己试验,成果如下:
概括的说,view中的layout_width形容的是本view和父容器的关系,比如button和包含它的LinearLayout;而view中的width是用来描述自己本身的。
如果你有swing编程的经验的话,就会知道,组件的大小是由包含它的布局管理器决定的,所以,如果view中有layout_width属性的话,不管有没有width属性,该view的形状是由父容器(即布局管理器LinearLayout)决定的,如下:
<Button android:id="@+id/button1" android:layout_width="match_parent" android:width="100dp" android:layout_height="wrap_content" android:layout_gravity="center" android:gravity="right" android:text="Bsdfsdfsdfsdfsdfsdfsdfsdf" />
如上图,不管width设置的多小,button的宽度是LinearLayout控制的。
如果在android:layout_width设置为"wrap_content"时,意思是让在容器中的view宽度随着view中内容的变化而变化,此时,如果存在width的话,那么view的宽度就是由他们共同控制的,如下:
<Button android:id="@+id/button1" android:layout_width="wrap_content" android:width="50dp" android:layout_height="wrap_content" android:text="Bsdfsdfsdfsdfsdfsdfsdfsdf" />
刚接触android,理解的肯定不到位,欢迎高手拍砖。
相关推荐
android:layout_width="fill_parent" android:layout_height="228.0dip" android:layout_marginTop="10.0dip" xmlns:android="http://schemas.android.com/apk/res/android"> android:layout_width="fill...
-<LinearLayout android:background="@drawable/aaa" android:weightSum="1" android:layout_height="match_parent" android:layout_width="match_parent" android:orientation="vertical" xmlns:android=...
-<LinearLayout android:background="@drawable/aaa" android:weightSum="1" android:layout_height="match_parent" android:layout_width="match_parent" android:orientation="vertical" xmlns:android=...
android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > android:layout_width="match_parent" android:layout_height="wrap_content" android:...
android:layout_width= match_parent android:layout_height= wrap_content > <Button android:layout_width= match_parent android:layout_height= wrap_content android:singleLine= true />...
android:layout_width="fill_parent" android:layout_height="fill_parent" zhy:position="left_top" zhy:radius="130dp" > android:layout_width="wrap_content" android:layout_height="wrap_content" ...
android:layout_width="fill_parent" android:layout_height="fill_parent"> <!-- FrameLayout - 层叠式布局。以左上角为起点,将 FrameLayout 内的元素一层覆盖一层地显示 --> <FrameLayout android...
android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" > android:id="@+id/ImageView1" android:layout_width="wrap_...
android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.wechat.wechat.MainActivity" android:orientation="vertical"> <include layout="@layout/top_...
-- 在主布局添加文本框和密码框 --> <TextView android:text = "@string/password" android:layout_width="match_parent" android:layout_height="wrap_content"/> <EditText android:id="@+id/password" android:...
android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal"/> android:id="@+id/digitalClock01" android:layout_width="wrap_content" ...
android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margin="15dip" android:background="@drawable/background_login" android:padding="15dip" > android:id="@+...
android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" > <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width=...
-- 在主布局添加文本框和密码框 --> <TextView android:text = "@string/password" android:layout_width="match_parent" android:layout_height="wrap_content"/> <EditText android:id="@+id/password" android:...
android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="上一题" android:textSize="15dp" /> android:id="@+id/ib2" android:layout_width="wrap_content" android:...
android:layout_width="fill_parent" android:layout_height="fill_parent" > android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> android:id=...
<ImageView android:layout_width="wrap_content" android:layout_height="100dp" android:src="@drawable/img" android:gravity="center" android:layout_span="4"/> </TableRow> <TableRow > <TextView/> ...
android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="24px" android:layout_weight="1" android:orientation="horizontal"> android:id="@+id/tv_solid...
android:layout_width="100dp" android:layout_height="wrap_content" android:layout_alignParentStart="true" android:layout_below="@+id/fill_text" android:layout_marginStart="80dp" android:...
android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="fill_horizontal" > android:id="@+id/address" android:layout_width="fill_parent" android:layout_height=...