android - 将 ImageView 固定到 LinearLayout 中最右侧的位置
问题描述
使用 XML 代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="8dp">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="8dp">
<TextView
android:id="@+id/crime_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Crime Title" />
<TextView
android:id="@+id/crime_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Crime date" />
</LinearLayout>
<ImageView
android:id="@+id/crime_police"
android:layout_width="117dp"
android:layout_height="50dp"
android:layout_gravity="fill_horizontal"
android:baselineAlignBottom="false"
android:src="@mipmap/handcuffs" />
</LinearLayout>
这是我最接近目标的方法,即将 ImageView 移动到此 LinearLayout 中的最右侧。这样我就可以使用 RecyclerView 创建以下示例:
是否可以仅通过使用 LinearLayout 来实现?Crime Title
或者,除了由和组成的 LinearLayout 之外,我还需要考虑使用其他类型的布局Crime date
吗?
提前致谢。
解决方案
无需更改布局中的任何内容
只需android:layout_weight="1"
在你的秒内使用LinearLayout
它就会起作用
试试这个
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="8dp">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="8dp">
<TextView
android:id="@+id/crime_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Crime Title" />
<TextView
android:id="@+id/crime_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Crime date" />
</LinearLayout>
<ImageView
android:id="@+id/crime_police"
android:layout_width="117dp"
android:layout_height="50dp"
android:layout_gravity="fill_horizontal"
android:baselineAlignBottom="false"
android:src="@drawable/ic_menu_send" />
</LinearLayout>
输出
推荐阅读
- azure-storage - 将 VSAM 文件从 Mainframe 一次性迁移到 Cloud Azure
- css - 不同浏览器上的滚动条行为
- html - 显示约束到父元素的子元素
- reactjs - 在 useEffect (Redux Saga) 中使用 Dispatch 时获得无限 API 调用
- ipad - 如何建立一个与我的第 8 代 iPad 具有相同分辨率的网站?
- sql-server - 如何在 SQL 中获得明智的产品总和
- c++ - 默认初始化和值初始化的含义?
- entity-framework-core - 扩展 Identity Server 4 的配置和操作数据上下文
- php - PHP 错误记录:为什么西里尔字符在日志文件中进行十六进制编码以及如何防止它?
- java - 使用kotlin或java的json对象内的数组内的Json对象