我在youtube上尝试了一个教程,但它没有用,当我点击按钮时没有任何反应。当我按下按钮时,我想要更改布局活动,并且还要在新布局上设置一个随机文本,让我们说其他10,在这个当前布局上我想要的按钮会随机将第一个文本更改为另一个文本。这是我使用过的代码,但没有用到。
@I无法添加代码,因为它不允许我在这里发布..它说类似的东西是无效的,但你看到图片中的所有内容,所以我做了所有的代码,当我按下我的按钮它没有做任何事情,可能是什么问题?如果你有任何想法或者你知道任何教程来帮助我实现我所说的我想要做的事情我会非常感激
@as你可以看到有一个字符串选项,当我点击我的按钮时它应该给我一个所有文本的文本,但它没有
sorry for image but it seems like those codes aren't good
<LinearLayout
android:layout_width="332dp"
android:layout_height="184dp"
android:layout_marginStart="36dp"
android:layout_marginLeft="36dp"
android:layout_marginTop="48dp"
android:orientation="vertical"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<Button
android:id="@+id/buttonsports"
android:layout_width="match_parent"
android:layout_height="129dp"
android:background="@drawable/ft"
tools:layout_editor_absoluteX="115dp"
tools:layout_editor_absoluteY="291dp" />
<TextView
android:id="@+id/sports"
android:layout_width="216dp"
android:layout_height="117dp"
android:text="TextView"
tools:layout_editor_absoluteX="95dp"
tools:layout_editor_absoluteY="246dp" />
</LinearLayout>
this is how big my text box is,the "sports" is the id for TextView which is "abc"
在您的xml中,您有一个LinearLayout
,您已将其设置为:
android:layout_height="184dp"
里面有一个高度为Button
:
android:layout_height="129dp"
所以对于TextView
下面有最大的55dp
,但你设置:
android:layout_height="117dp"
这意味着至少有一半的TextView
不可见。
在您的代码中,当您单击TextView
时,您将随机文本设置为Button
。
你说什么都没发生。
是否存在文本正在设置但你无法看到它的情况,因为TextView
大多是隐藏的?
改变视图的高度,你会发现。