java - 为什么按钮不稳定
问题描述
为什么按钮不稳定
从下图可以看出,为什么其他手机的按钮在不同的地方
你能帮我解决这个问题吗
我希望每部手机上的按钮都位于同一个位置。(如第一张图片)
我的手机
我的朋友电话(huwai)
我的朋友电话(三星)
我使用的代码如下。如何更改这些代码才能解决此问题?我对编码了解不多
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@drawable/v"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@drawable/y"
android:text="Değiştir"
android:textColor="#ffffff"
android:layout_marginStart="20dp"
android:layout_marginBottom="60dp"
android:textSize="15dp"
android:onClick="random"/>
<Button
android:id="@+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:background="@drawable/y"
android:layout_marginBottom="60dp"
android:layout_marginEnd="20dp"
android:text="Kopyala"
android:textColor="#ffffff"
android:onClick="kopyala"
android:textSize="15dp" />
<Button
android:text="Paylaş"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:background="@drawable/y"
android:layout_marginBottom="60dp"
android:layout_marginEnd="140dp"
android:textColor="#ffffff"
android:textSize="15dp"
android:id="@+id/button"
android:onClick="paylas"/>
</RelativeLayout>
解决方案
尝试在水平方向的线性布局中添加权重(将视图彼此相邻放置)
<RelativeLayout 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="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="3">
<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button 1"
android:textColor="#ffffff"
android:textSize="15dp" />
<Button
android:id="@+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button 2"
android:textColor="#ffffff"
android:textSize="15dp" />
<Button
android:id="@+id/btn3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button 3"
android:textColor="#ffffff"
android:textSize="15dp" />
</LinearLayout>
</RelativeLayout>
推荐阅读
- protractor - 量角器 - 将值从一个描述 /IT 块传递到另一个
- postgresql - Spring Boot 1.5.3 创建比 application.properties 中指定更多的连接
- oracle - TKPROF 输出中的 Starts 数据是什么?
- r - 遇到 R 闪亮错误:非数字矩阵范围
- qt - 滚动时如何管理ListView中item的位置
- java - Hazelcast spring 模式配置错误
- ruby-on-rails - 查询所有不包含特定关联的记录
- jquery - jquery 对话框如何获取 id 元素触发对话框
- algorithm - Big O 复杂性的答案可能不止一个吗?
- python-3.x - 将一个数据框中的一列元素添加到另一个数据框中另一列的元素中