android - 滚动和缩放Textview之间的冲突
问题描述
我对 Textview 有一些问题。我已经为我的应用程序编写了这段代码。如果需要,我希望能够捏一下来缩放和滚动 Textview。我编写了捏缩放的代码,它可以正常工作,但是如果我插入 textview 滚动的代码,它就不起作用,但滚动工作正常。如果我删除滚动代码,我可以通过捏合来缩放,但如果文本对于页面来说太长,我就无法滚动它。我的代码有什么问题?
布局代码:
<TextView
android:id="@+id/tv_testo_canzone"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="40dp"
android:layout_marginTop="90dp"
android:scrollbars="vertical"
android:text="TextView"
android:textAlignment="center"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
主要代码:
tv_testo_canzone = (TextView) findViewById(R.id.tv_testo_canzone);
tv_titolo = (TextView) findViewById(R.id.tv_titolo_canz);
tv_artista = (TextView) findViewById(R.id.tv_artista_canz);
tv_testo_canzone.setMovementMethod(new ScrollingMovementMethod());
linearLayout1 = (RelativeLayout) findViewById(R.id.layout_canzone);
try {
reader = new BufferedReader(
new InputStreamReader(getAssets().open(nomeTxt)));
// do reading, usually loop until end of file reading
String mLine;
while ((mLine = reader.readLine()) != null) {
text.append(mLine);
text.append('\n');
}
} catch (IOException e) {
Toast.makeText(getApplicationContext(),"Error reading file!",Toast.LENGTH_LONG).show();
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
//log the exception
}
}
tv_testo_canzone.setText((CharSequence) text);
}
解决方案
代码没有问题,认为当您使用 ScrollView 时,所有子视图都不会收到手势,因为它们都是由父 ScrollView 处理的
推荐阅读
- java - hibernate在sql server查询中添加nolock
- python - 优化python selenium webscraping
- regex - 整数或带有四分之一小数的数字的正则表达式
- c# - WPF 无法在 Listview WPF 中滚动 ItemsControl
- mysql - Mysql工作台创建函数
- laravel - 具有非默认primaryKey的雄辩关系(belongsTo,hasMany)
- upload - 将 txt 文件上传到 hyperledger composer 并将它们与资产相关联
- prolog - Prolog - 如何进行循环排列
- spring-boot - 在运行时使用 Spring Boot Actuator 刷新端点刷新 Spring Redis 缓存管理器 Bean
- angular - Angular/RxJS:即使发生错误,也要保持间隔运行