android studio按钮文本视图手势



它们一直在移动,我该如何让它们固定呢

我做了一个随机的应用程序,但是当你按下按钮时,textview和按钮不断变化。我该如何预防呢?如下图所示

输入图片描述

输入图片描述

输入图片描述

我在这些

中使用的代码
<TextView
android:id="@+id/tw1"
android:textSize="15dp"
android:text=""
android:gravity="center"
android:textIsSelectable="true"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<Button 
android:id="@+id/btn1"
android:text="random"
android:textSize="50dp"
android:layout_centerInParent="true"
android:layout_alignParentBottom="true"
android:layout_marginTop="200dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

问题是你正在使用LinearLayout默认情况下,它的子节点是水平布局的。基于TextView文本的长度按下按钮向右(水平)。如果你想改变这种行为,考虑使用不同的布局或改变当前LinearLayout的方向。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" 
android:orientation="vertical">

LinearLayout child orientation

最新更新