android - Android 三项并排
问题描述
我正在尝试为我的 recyclerview 创建一个布局,其中三个项目水平相邻。
我希望通过 LinearLayout 来实现这一点,但最后一项(ImageButton)不会出现。我也一直在尝试权重组合。
有没有好的方法来实现这一目标?以下是我当前的布局文件。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal">
<TextView
android:id="@+id/textView_option"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/option"
android:layout_margin="15dp"
android:textSize="20dp"
/>
<EditText
android:id="@+id/editText_option"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:lines="1" />
<ImageButton
android:layout_width="35dp"
android:layout_height="35dp"
android:src="@drawable/icon_minus"
android:scaleType="fitCenter"
android:background="@null"
android:layout_weight="2"
/>
</LinearLayout>
解决方案
尝试用下面的代码替换它
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="3"
android:orientation="horizontal">
<TextView
android:id="@+id/textView_option"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:text="option"
android:layout_weight="1"
android:textSize="20dp" />
<EditText
android:id="@+id/editText_option"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:layout_weight="1"
android:lines="1" />
<ImageButton
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_weight="2"
android:background="@null"
android:scaleType="fitCenter"
android:src="@drawable/icon_minus" />
</LinearLayout>
推荐阅读
- angularjs - 角度中的 if 和 else if 语句
- iphone - Aframe mobile 无法检测设备的方向
- python - 如何在 PyCharm 中将所有相对导入转换为绝对导入?
- php - 如何在没有引号的情况下获得数组结果
- android - 为什么使用隐式意图时不需要互联网许可?
- angular - 仅来自角度 7 的 PUT 请求出现“被 CORS 策略阻止”错误
- javascript - Discord.JS 中的轮询命令有问题。你如何解决这个问题?
- excel - RangetoHTML 子程序突然停止工作
- c# - 有没有办法直接从 C# 应用程序将文件写入 Azure Blob 存储?
- html - 样式标签在 gmail 中不起作用,即使文档另有说明