Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Android 控件(button)对齐方法实现详解大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
1,android:orientation
布局方向。horizontal是让所有的子元素按水平方向从左到右排列, vertical是让所有的子元素按竖直方向从上到下排列。

2,android:gravity 与 android:layout_gravity的区别android:gravity是指定本元素的子元素相对它的对齐方式。

android:layout_gravity是指定本元素相对它的父元素的对齐方式。
例如:
下面这里的linearlayout的android:gravity设为right,有两个子元素Button01和Button02。
java代码

<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout xmlns:android=”http://scheR_719_11845@as.android.com/apk/res/android”
android:orientation=”vertical”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:gravity=”right”
>
<Button android:text=”button01″ android:id=”@+id/Button01″ android:layout_width=”wrap_content” android:layout_height=”wrap_content”></Button>
<Button android:text=”button02″ android:id=”@+id/Button02″ android:layout_width=”wrap_content” android:layout_height=”wrap_content”></Button>
</LinearLayout>

这个main.xml里的LinearLayout也是有两个子元素Button01和Button02。Button01的android:layout_gravity设为”left”,Button02的 android:layout_gravity设为”right”
java代码

<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout xmlns:android=”http://scheR_719_11845@as.android.com/apk/res/android”
android:orientation=”vertical”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
>
<Button
android:layout_gravity=”left”
android:text=”button01″
android:id=”@+id/Button01″
android:layout_width=”wrap_content” a
ndroid:layout_height=”wrap_content”></Button>
<Button
android:layout_gravity=”right”
android:text=”button02″
android:id=”@+id/Button02″
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”>
</Button>
</LinearLayout>

FameLayout布局
FrameLayout是最简单的一个布局对象。它被定制为你屏幕上的一个空白备用区域,之后你可以在其中填充一个单一对象―比如,一张你要发布的图片。所有的子元素将会固定在屏幕的左上角;你不能为FrameLayout中的一个子元素指定一个位置。后一个子元素将会直接在前一个子元素之上进行覆盖填充,把它们部份或全部挡住(除非后 一个子元素是透明的)。

xml属性
1,用Xml文件来定义界面,然后Activity的setContentView方法根据xml文件里的定义来创建真正的控件对象。好比说xml文件是设计图纸,setContentView是生产机器,它依照图纸生产出各种各样的杯具和洗具。
2,FrameLayout的xml属性来自三个地方:继承下来的,嵌套类定义的,自身类定义的。
3,具的属性可查阅官方文档。下面是刚才遇到的几个属性
java代码

android:id
//这个xml属性是继承自android.view类的xml属性。它为framelayout提供一个唯一识别符号,之后,程序要用到它时可以用View.findViewById() 或Activity.findViewById()来找到它。
android:layout_width: 布局宽
android:layout_height: 布局高
//它们的取值是fill_parent或wrap_content。
fill_parent :在x轴或则y轴上充满父容器的空间。
wrap_content :framelayout里的元素有多少宽高就多少宽高,
//这两个属性都是定义在Android.widget.FrameLayout的嵌套类android.widget.FrameLayout.LayoutParams里。
android:BACkground:背景
android:foreground :前景

大佬总结

以上是大佬教程为你收集整理的Android 控件(button)对齐方法实现详解全部内容,希望文章能够帮你解决Android 控件(button)对齐方法实现详解所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:button对齐