【问题标题】:android studio button textwiew gestures [closed]android studio按钮textwiew手势[关闭]
【发布时间】:2021-05-03 05:57:34
【问题描述】:

他们一直在移动,我如何让他们固定

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

enter image description here

enter image description here

enter image description here

我在这些中使用的代码

<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" />

【问题讨论】:

  • 你能给我们你的Java代码吗?你在哪里设置了这个按钮的监听器?也许不要将 centerInParent 与 alignParentBottom 一起使用。如果您想将按钮置于水平线上,只需使用 centerHorizo​​ntal。这样您就可以将其推到底部并希望它位于布局的中心。
  • public void onClick(View p1)
  • 我不是这个意思。编辑您的问题并将您的 Activity.class 代码放在那里。
  • 我正在使用手机助手。所以我找不到你说的那个文件。我只想固定按钮。
  • schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent">

标签: java android xml android-studio textview


【解决方案1】:

问题在于您使用的是 LinearLayout 并且它的子级默认情况下是水平布局的。根据您的 TextView 中文本的长度,将 Button 向右(水平)“”。如果您想更改此行为,请考虑使用不同的布局或更改当前 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 children orientation

【讨论】:

  • 这就是为什么完整的代码在问题中很重要。不错!
猜你喜欢
  • 1970-01-01
  • 2011-09-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-25
  • 2021-07-07
  • 1970-01-01
相关资源
最近更新 更多