android - Android Studio 将元素与它们下的其他元素对齐
问题描述
您好,我正在使用 android studio 进行移动应用程序开发,我需要制作 3 个LinearLayouts
相同的大小。问题是第一个元素包含不同的元素。我需要拉伸第一个元素以使其具有与其他元素完全相同的大小。我想我可以以某种方式知道这是元素的大小并将值设置为第一个元素。也许有可能以某种方式对齐它们?这就是它的外观。感谢帮助!
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
tools:context=".MainView.MainActivity"
android:orientation="vertical"
android:paddingTop="100dp">
<!-- rounds View -->
<TextView
style="@style/option_type_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/rounds" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<Button
android:id="@+id/minus_round_button"
style="@style/change_value_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/minus" />
<EditText
android:id="@+id/round_minutes"
style="@style/option_input_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/default_time" />
<Button
android:id="@+id/plus_round_button"
style="@style/change_value_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/plus"/>
</LinearLayout>
<!-- end rounds View-->
<!-- work View -->
<TextView
style="@style/option_type_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/work" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<Button
android:id="@+id/minus_work_button"
style="@style/change_value_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/minus" />
<EditText
android:id="@+id/work_minutes"
style="@style/option_input_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/default_time" />
<TextView
style="@style/option_input_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=":"/>
<EditText
android:id="@+id/work_seconds"
style="@style/option_input_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/default_time" />
<Button
android:id="@+id/plus_work_button"
style="@style/change_value_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/plus"/>
</LinearLayout>
<!-- end Work View-->
<!-- rest View -->
<TextView
style="@style/option_type_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/rest" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<Button
android:id="@+id/minus_rest_button"
style="@style/change_value_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/minus" />
<EditText
android:id="@+id/rest_minutes"
style="@style/option_input_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/default_time" />
<TextView
style="@style/option_input_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=":"/>
<EditText
android:id="@+id/rest_seconds"
style="@style/option_input_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/default_time" />
<Button
android:id="@+id/plus_rest_button"
style="@style/change_value_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/plus"/>
</LinearLayout>
<!-- end Rest View-->
</LinearLayout>
解决方案
使您的第一个元素如下:
<TextView
style="@style/option_type_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/rounds" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<Button
android:id="@+id/minus_round_button"
style="@style/change_value_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/minus" />
<EditText
android:id="@+id/round_minutes"
style="@style/option_input_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/default_time" />
<Button
android:id="@+id/plus_round_button"
style="@style/change_value_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/plus"/>
</LinearLayout>
推荐阅读
- javascript - 无法从“navigation/MainNavigator.jsx”解析 X
- sql-server - MS SQL 使用另一个表中的 WHERE 条件
- c++ - 如何在 c++ 中获取有关崩溃程序的一些信息以供将来调试
- sql - 如何通过使用 PostgreSQL 中的联接子句来使用具有动态列数的交叉表
- javascript - 能够在 Jest 中将 json 文件转换为 js
- three.js - 如何使地板完全变白并带有阴影
- java - Zxing NotFoundException Java
- python - 如何在 python 脚本中使用这个 FFMPEG 命令?
- python - Web Scraping Mahindra 网站
- javascript - 将图像发送到 MSTeams 中的深层链接 URL