Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java android studio按钮文本查看手势_Java_Android_Xml_Android Studio_Textview - Fatal编程技术网

Java android studio按钮文本查看手势

Java android studio按钮文本查看手势,java,android,xml,android-studio,textview,Java,Android,Xml,Android Studio,Textview,他们不断地移动,我怎样才能使他们固定 我做了一个随机应用程序,但当你按下按钮时,文本视图和按钮会不断变化。我怎样才能防止这种情况?如下图所示 我在这些文件中使用的代码 <TextView android:id="@+id/tw1" android:textSize="15dp" android:text="" android:gravity="cent

他们不断地移动,我怎样才能使他们固定

我做了一个随机应用程序,但当你按下按钮时,文本视图和按钮会不断变化。我怎样才能防止这种情况?如下图所示

我在这些文件中使用的代码

<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 xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:orientation="vertical">


您能给我们您的Java代码吗?你在哪里设置了这个按钮的侦听器?也许不要将centerInParent与alignParentBottom一起使用。如果要将按钮置于水平线的中心,只需使用centerHorizontal。这样你就把它推到了底部,并希望它位于布局的中心。public void onClick(视图p1)这不是我的意思。编辑你的问题并将你的Activity.class代码放在那里。我正在使用手机上的aide。这就是为什么我找不到你说的文件。我只想锁定按钮。这就是为什么完整代码在问题中很重要的原因。美好的