Android Linear/Relative Layout - how to quot;auto sizequot; object in the middle (3 objects)(Android线性/相对布局-如何自动调整中间对象的大小(3个对象))
本文介绍了Android线性/相对布局-如何自动调整中间对象的大小(3个对象)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Android中有两个线性(也尝试过相对)布局的案例。一种是水平的,另一种是垂直的。让我们从水平开始:
类似于:
<LinearLayout ... >
<Button ... layout:gravity = "left" layout:width = "wrap_content"/>
<TextView ... layout:width = ??????? />
<Image .... layout:gravity = "right" layout:width = "wrap_content"/>
</LinearLayout>
我希望按钮保持在左侧,图像保持在右侧(紧贴在文本视图的末尾,而不仅仅是文本视图的右侧),文本视图(可能带有自动显示或其他功能)保持在中间。如果我输入TextView Width="Fill/Match_Parent,它会将图像发送出屏幕。如果我输入WRAP_CONTENT,则图像不会停留在屏幕的右侧。我也尝试了相对布局,但没有成功。
垂直方向的大小写相同,我的情况类似于:
<LinearLayout ...>
<LinearLayout .... layout:height = "wrap_content" layout:gravity= "top" />
<ListView layout:height = ???????>
<LinearLayout ... layout:height = "wrap_content" layout:gravity = "bottom" />
</LinearLayout>
这里也有同样的要求。我希望第一个L布局留在顶部,列表视图自动大小之间的他们和第二个线性布局留在底部。(假设我正在尝试创建一个类似于iPhone中的UITableView的视图,该视图底部有一个导航栏、项目列表和一个工具栏。第一个LinearLayout是导航栏,列表视图是单元格,第二个LinearLayout是工具栏)。
有什么建议吗?更喜欢使用XML解决方案。
推荐答案
只需使用RelativeLayout即可完成此操作。
水平对齐
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="something"
/>
<TextView
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/image"
android:layout_toRightOf="@+id/button" />
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="@drawable/icon" />
</RelativeLayout>
垂直对齐
<LinearLayout
android:id="@+id/linear_top"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ListView
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/linear_top"
android:layout_above="@+id/linear_bottom" />
<LinearLayout
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
</RelativeLayout>
这篇关于Android线性/相对布局-如何自动调整中间对象的大小(3个对象)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:Android线性/相对布局-如何自动调整中间对象的大小(3个对象)


猜你喜欢
- android 4中的android RadioButton问题 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01