android - 有没有办法在线性布局中从底部堆叠小部件?
问题描述
定义 aLinearlayout
时,像Button
,这样的小部件Edittext
将从顶部开始堆叠。例如,下面的代码将像这样显示
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:text="button"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:text="edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:text="button"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:text="edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
是否可以不使用从布局底部开始添加按钮和编辑文本layout_weight
?
解决方案
添加android:gravity="bottom"
到您的根布局:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom" \\ add this line
android:orientation="vertical">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="edittext" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="button" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="edittext" />
</LinearLayout>
推荐阅读
- react-native - 使用 React Native 检测从应用程序设置/背景返回
- c - Watcom 编译器中的长文件名支持
- ios - iOS 项目无法识别对 Firebase SDK 的 Database.database().reference() 调用,错误为“未解析的标识符数据库”
- javascript - 无法删除由 Webpack 创建的供应商目录
- c++ - 为不同的容器定义一个函数
- php - 从表中查询并从另一个表列中获取值
- r - SF中的溶解线
- python-3.x - 使用来自 TextChoices 模型的 html 代码显示笑脸
- vb.net - 您可以使用不同的大小写符号从 HttpContext.Current.Request.Url.AbsoluteUri 和 HttpContext.Current.Request.RawUrl 克服 vb.net 吗?
- compilation - 为什么在 Fortran 运行时未解析 present()?