android - 在按钮文本中添加新行并增加按钮大小时如何不更改按钮的大小?
问题描述
例如,我有一个垂直线性布局,android:layout_weight="1"
里面有 2 个按钮。问题是,如果我在按钮文本中添加新行
并增加其大小,则该按钮会变得比另一个大。如果更改了文本大小,如何使按钮不更改其大小?
<?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:background="#00ACC1"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<Button
android:id="@+id/button18"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:background="@drawable/colorofbuttons"
android:fontFamily="@font/architects_daughter"
android:text="Mom"
android:textAllCaps="false"
android:textColor="#ffffff"
android:textSize="18sp"></Button>
<Button
android:id="@+id/button19"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:background="@drawable/colorofbuttons"
android:ellipsize="end"
android:fontFamily="@font/architects_daughter"
android:maxLines="1"
android:text="My Name"
android:textAllCaps="false"
android:textColor="#ffffff"
android:textSize="18sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<Button
android:id="@+id/button20"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:background="@drawable/colorofbuttons"
android:fontFamily="@font/architects_daughter"
android:text="Dad"
android:textAllCaps="false"
android:textColor="#ffffff"
android:textSize="18sp" />
<Button
android:id="@+id/button21"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:background="@drawable/colorofbuttons"
android:fontFamily="@font/architects_daughter"
android:text="Girl"
android:textAllCaps="false"
android:textColor="#ffffff"
android:textSize="18sp" />
</LinearLayout>
</LinearLayout>
解决方案
在您的按钮代码REPLACE
android:layout_height="wrap_content"
和
android:layout_height="0dp"
它会工作:)
推荐阅读
- ios - 在 SwiftUI 中继承 ObservableObject 时不会触发视图刷新
- bash - 使用 ls -lR 忽略给定的正则表达式
- php - Laravel Blade, Escape {{ }} Echo
- javascript - AWS S3 不能将“alpha”字符存储在大文件中?
- android - 如何在单个活动应用程序上使用 dagger2 处理子组件?
- laravel - 政策未正确触发的 Laravel 问题?
- javascript - Vue.js - onclick 事件不会触发
- java - 从键盘(1 值参数)或文件(0 值参数)读取的方法在 0 参数处无法正常工作
- makefile - 警告:作业服务器不可用:使用 -j1。将“+”添加到父制定规则
- android - 机器学习套件条码检测 - isOperational() 始终为假 - 未找到可接受的模块