android - 有没有办法在屏幕的两端显示两个 android 按钮
问题描述
我试图让我的两个按钮显示在屏幕的两端。
这是我的 XML:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center">
<ImageButton
android:id="@+id/previous_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:src="@drawable/arrow_left" />
<ImageButton
android:id="@+id/next_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:src="@drawable/arrow_right" />
</LinearLayout>
</FrameLayout>
这就是我想要完成的(底部箭头按钮是我想要修改的)但它们一直在左侧或中间挤在一起。(上面的代码把它们放在中间。我想要一个在左边,一个在右边。
解决方案
您可以添加一个空视图并设置layout_weight
如下:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:orientation=horizontal">
<ImageButton
android:id="@+id/previous_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/arrow_left" />
<View
android:layout_height="match_parent"
android:layout_width="0dp"
android:width="0dp"
android:layout_weight="1" />
<ImageButton
android:id="@+id/next_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/arrow_right" />
</LinearLayout>
</FrameLayout>
推荐阅读
- javascript - 在 Swift 中调用 NPM (Javascript)
- wordpress - “failed_to_connect_to_backend” - 502 网站暂时关闭
- linux - 将 Linux 文件复制到另一个位置
- javascript - 整个组件的不必要的重新渲染
- entity-framework - 使用 IMiddleware 后续问题时添加自定义中间件不起作用
- node.js - 更改源代码不会使用 docker-compose 和 mern 堆栈上的卷进行实时更新
- android - 从本机平台创建一个视图并检索它颤动通道
- sql - 一行 SQL where 子句中有多个 '='
- powershell - 使用 Microsoft 团队错误异常调用“GetRemoteNewCsOnlineSession”配置应用程序访问策略
- amazon-web-services - 存储错误:应用程序尝试写入没有提供 id 的对象,但存储中已包含 id
对于这个对象