gpt4 book ai didi

android 可滚动 TextView 在 ScrollView 中不起作用

转载 作者:行者123 更新时间:2023-11-29 16:02:45 26 4
gpt4 key购买 nike

我正在开发 1 个应用程序,因为我需要 1 个 scrollview 在此 ScrollView 中我需要放置滚动 textview/webview(必须显示一些静态字符串)但必须可滚动在 scrollview 内但不工作

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/white" >
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_below="@+id/img_view_flag"
android:layout_marginTop="17dp"
android:paddingBottom="20dip">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >



<TextView
android:id="@+id/tv_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/rel_layout"
android:layout_marginTop="15dp"
android:maxLines="2"
android:scrollbars="vertical"
android:text="Medium Text"
android:paddingBottom="10dip"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/black" />
</LinearLayout>
</ScrollView>

</RelativeLayout>

在 myjava 文件中我做了...

scrollView1 = (ScrollView) findViewById(R.id.scrollView1);
// scrollView2 = (ScrollView) findViewById(R.id.scrollView2);
tv = (TextView) findViewById(R.id.tv_desc);
tv.setText("this is 1\n"+"this is 2"+"\n this ix 3\n"+"this is 4\n\n"+"this is 5\n" );

scrollView1.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
// TODO Auto-generated method stub Log.v("PARENT",
// "PARENT TOUCH");
Log.v("PARENT", "PARENT TOUCH");
findViewById(R.id.tv_desc).getParent()
.requestDisallowInterceptTouchEvent(false);
return false;
}
});
tv.setOnTouchListener(new OnTouchListener() {

@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
Log.v("TextView", "CHILD TOUCH");
arg0.getParent().requestDisallowInterceptTouchEvent(true);
return false;
}
});

但不适合我....有什么问题或我错过了什么?

最佳答案

你必须在你的代码中使用下面一行来使 TextView 可滚动..

yourTextView.setMovementMethod(new ScrollingMovementMethod())

关于android 可滚动 TextView 在 ScrollView 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22472269/

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