扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
LinearLayout布局:
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button1"
/>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button2"
/>
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Button3"
/>
LinearLayout布局的嵌套:
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button1"
/>
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
android:text="Button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Button3"
/>
Layout_weight属性:
所有的组件都有这个属性,不设置的情况下默认为0,其属性表示当前有多大视图就占据多大视图
如果其值高于0,则表示将父视图中的可用空间进行分割
示例代码如下:
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button1"
android:layout_weight="1"
/>
android:text="button4"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"
/>
线性布局中常用的属性:
1:gravity:每个组件默认其值为左上角对齐。这个属性可以调整组件对齐方式比如如何向左。向右或者居中对齐等、
2:padding边距的填充,也称内边距.指的是当前布局与包含的组件之间的边距
android:paddingTop
android:paddingBottom
android:paddingLeft
android:paddingRight
android:padding表示周围四方向个边距统一调整
3:layout_margin:外边距。指的是与其他组件之间的边距。
android:layout_marginTop
android:layout_marginBottom
android:layout_marginLeft
android:layout_marginRight
android:layout_margin表示设置四方向边距统一调整
一个比较综合的例子:
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button1"
android:layout_gravity="bottom"
android:paddingTop="10dp"
/>
android:text="button4"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="bottom"
android:layout_marginLeft="50dp"
android:layout_marginTop="30dp"
/>
android:text="button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:paddingLeft="60dp"
android:paddingBottom="60dp"
/>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button3"
android:layout_gravity="right"
/>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button6"
android:layout_gravity="right"
android:layout_marginRight="40dp"
android:layout_marginTop="40dp"
/>
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流