gpt4 book ai didi

java - ScrollView 不随 onTouch 滚动

转载 作者:行者123 更新时间:2023-12-01 18:38:43 25 4
gpt4 key购买 nike

我的 ScrollView 没有滚动。我有一种感觉,这可能是由于我使用的“onTouch”方法,而不是滚动,而是增加了显示的计数器。我试图找到一些解决方案,但似乎没有一个与我的解决方案直接相关,并且任何更改 ScrollView 的尝试都不起作用。我不知道如何解决这个问题,任何帮助将不胜感激。

Java 代码

package com.alanlyne.tbm.Variables.varL;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.os.SystemClock;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.alanlyne.tbm.Menu.Menu;
import com.alanlyne.tbm.Menu.menuCounter;
import com.alanlyne.tbm.R;
import com.alanlyne.tbm.Variables.Var;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;

public class varL2 extends AppCompatActivity {
TextView t0, t1, t2, t3, t4, t5, t6, t7, t8, x;
Button b1;
int counter = 0;
DatabaseReference databaseName;
private long mLastClickTime = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_var_l2);
databaseName = FirebaseDatabase.getInstance().getReference("counter");

t0 = findViewById(R.id.t0);
t1 = findViewById(R.id.t1);
t2 = findViewById(R.id.t2);
t3 = findViewById(R.id.t3);
t4 = findViewById(R.id.t4);
t5 = findViewById(R.id.t5);
t6 = findViewById(R.id.t6);
t7 = findViewById(R.id.t7);
t8 = findViewById(R.id.t8);
b1 = findViewById(R.id.b1);

x = findViewById(R.id.x);
x.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

Intent x = new Intent(varL2.this, Var.class);
startActivity(x);
}
});

View view = findViewById(R.id.ScrollView01);
view.setOnTouchListener(new View.OnTouchListener() {

@Override
public boolean onTouch(View view, MotionEvent event) {

if (SystemClock.elapsedRealtime() - mLastClickTime < 500) {
System.out.println("Fun");
}
else{
mLastClickTime = SystemClock.elapsedRealtime();

counter++;

System.out.println(counter);
if (counter > 0) {
TextView tv = findViewById(R.id.t1);
tv.setVisibility(View.VISIBLE);

}
if (counter > 1) {
TextView tv = findViewById(R.id.t2);
tv.setVisibility(View.VISIBLE);
}
if (counter > 2) {
TextView tv = findViewById(R.id.t3);
tv.setVisibility(View.VISIBLE);
}
if (counter > 3) {
TextView tv = findViewById(R.id.t4);
tv.setVisibility(View.VISIBLE);
}
if (counter > 4) {
TextView tv = findViewById(R.id.t5);
tv.setVisibility(View.VISIBLE);
}
if (counter > 5) {
TextView tv = findViewById(R.id.t6);
tv.setVisibility(View.VISIBLE);
}
if (counter > 6) {
TextView tv = findViewById(R.id.t7);
tv.setVisibility(View.VISIBLE);
}
if (counter > 7) {
TextView tv = findViewById(R.id.t8);
tv.setVisibility(View.VISIBLE);
}
if (counter > 8) {
Button b1 = findViewById(R.id.b1);
b1.setVisibility(View.VISIBLE);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent Menu = new Intent(varL2.this, Var.class);
startActivity(Menu);
addCounter();
}
});
}}
return true;
}
});
}
private void addCounter(){
if(Menu.counter == 12) {
Menu.counter = 13;
menuCounter counter = new menuCounter(Menu.counter);
databaseName.child(FirebaseAuth.getInstance().getCurrentUser().getUid()).setValue(counter);
System.out.println("AHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH");
}
}
}

XML 代码

<?xml version="1.0" encoding="utf-8"?>

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bgcolour"
tools:context=".Variables.varL.varL2">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent">

<TextView
android:id="@+id/t0"
android:layout_width="300sp"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:background="@drawable/edit_round"
android:gravity="center"
android:padding="10dp"
android:text="There are 8 primitive data types for creating variables in Java."
android:textColor="@android:color/black"
android:textColorHighlight="#FF000000"
android:textSize="15sp"
android:visibility="visible"
app:layout_constraintBottom_toTopOf="@+id/t1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/t1"
android:layout_width="300sp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="@drawable/edit_round"
android:gravity="center"
android:padding="10dp"
android:text="byte\n8 bit integer\n-128 to 127\nDefault of 0"
android:textColor="@android:color/black"
android:textColorHighlight="#FF000000"
android:textSize="15sp"
android:visibility="invisible"
app:layout_constraintBottom_toTopOf="@+id/t2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.495"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/t0" />

<TextView
android:id="@+id/t2"
android:layout_width="300sp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="@drawable/edit_round"
android:gravity="center"
android:padding="10dp"
android:text="short\n16 bit integer\n-32768 to 32767\nDefault of 0"
android:textColor="@android:color/black"
android:textColorHighlight="#FF000000"
android:textSize="15sp"
android:visibility="invisible"
app:layout_constraintBottom_toTopOf="@+id/t3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.495"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/t1" />

<TextView
android:id="@+id/t3"
android:layout_width="300sp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="@drawable/edit_round"
android:gravity="center"
android:padding="10dp"
android:text="int\n32 bit integer\n-2147483648 to 2147483647\nDefault of 0"
android:textColor="@android:color/black"
android:textColorHighlight="#FF000000"
android:textSize="15sp"
android:visibility="invisible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.495"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/t2" />

<TextView
android:id="@+id/t4"
android:layout_width="300sp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="@drawable/edit_round"
android:gravity="center"
android:padding="10dp"
android:text="long\n64 bit integer\n-9223372036854775808 to 9223372036854775807\nDefault of 0L"
android:textColor="@android:color/black"
android:textColorHighlight="#FF000000"
android:textSize="15sp"
android:visibility="invisible"
app:layout_constraintBottom_toTopOf="@+id/t5"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.495"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/t3" />

<TextView
android:id="@+id/t5"
android:layout_width="300sp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="@drawable/edit_round"
android:gravity="center"
android:padding="10dp"
android:text="float\nDecimal point number\n1.5*10^-45 to 3.4*10^38\nDefault of 0.0f"
android:textColor="@android:color/black"
android:textColorHighlight="#FF000000"
android:textSize="15sp"
android:visibility="invisible"
app:layout_constraintBottom_toTopOf="@+id/t6"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.495"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/t4" />


<TextView
android:id="@+id/t6"
android:layout_width="300sp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="@drawable/edit_round"
android:gravity="center"
android:padding="10dp"
android:text="double\nDecimal point number\n5.0*10^-324 to 1.7*10^308\nDefault of 0.0"
android:textColor="@android:color/black"
android:textColorHighlight="#FF000000"
android:textSize="15sp"
android:visibility="invisible"
app:layout_constraintBottom_toTopOf="@+id/t7"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/t5" />

<TextView
android:id="@+id/t7"
android:layout_width="300sp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="@drawable/edit_round"
android:gravity="center"
android:padding="10dp"
android:text="char\nA unicode character e.g 'a','b'\n(\u0000 to \uffff) or (0 to 65535)\nDefault of null"
android:textColor="@android:color/black"
android:textColorHighlight="#FF000000"
android:textSize="15sp"
android:visibility="invisible"
app:layout_constraintBottom_toTopOf="@+id/t8"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.504"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/t6" />

<TextView
android:id="@+id/t8"
android:layout_width="300sp"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="@drawable/edit_round"
android:gravity="center"
android:padding="10dp"
android:text="boolean\nLogical true or false\ntrue or false\nDefault of false"
android:textColor="@android:color/black"
android:textColorHighlight="#FF000000"
android:textSize="15sp"
android:visibility="invisible"
app:layout_constraintBottom_toTopOf="@+id/b1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.504"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/t7" />

<Button
android:id="@+id/b1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="150dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="150dp"
android:layout_marginBottom="20dp"
android:background="@drawable/b_round"
android:text="Continue"
android:textColor="@android:color/white"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/t8" />

<TextView
android:id="@+id/x"
android:layout_width="15dp"
android:layout_height="35dp"
android:layout_marginStart="10dp"
android:text="x"
android:textColor="@android:color/white"
android:textSize="30sp"
app:layout_constraintBottom_toTopOf="@+id/t0"
app:layout_constraintEnd_toEndOf="@+id/t0"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />


</androidx.constraintlayout.widget.ConstraintLayout>

</ScrollView>

最佳答案

通过使用

解决了该问题
View view = findViewById(R.id.ScrollView01);

引用约束布局的id而不是 ScrollView 。

关于java - ScrollView 不随 onTouch 滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59988410/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com