繁体   English   中英

TextView滚动不起作用

[英]TextView scrolling does not work

这是使用TextView缩放应用程序的关键点。 我想缩放TextView内容。

public class sukharta extends AppCompatActivity {
    TextView scaleGesture;
    ScaleGestureDetector scaleGestureDetector;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sukharta);
        scaleGesture = (TextView)findViewById(R.id.textView);
        scaleGesture.setText(R.string.sukharta);
        scaleGestureDetector = new ScaleGestureDetector(this, (ScaleGestureDetector.OnScaleGestureListener) new simpleOnScaleGestureListener());
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getLayoutInflater().inflate(R.layout.activity_sukharta, (ViewGroup) menu);
        return true;
    }
    @Override
    public boolean onTouchEvent(MotionEvent event) {
        // TODO Auto-generated method stub
        scaleGestureDetector.onTouchEvent(event);
        return true;
    }

    public class simpleOnScaleGestureListener extends
        ScaleGestureDetector.SimpleOnScaleGestureListener {

        @Override
        public boolean onScale(ScaleGestureDetector detector) {
            // TODO Auto-generated method stub
            float size = scaleGesture.getTextSize();
            Log.d("TextSizeStart", String.valueOf(size));

            float factor = detector.getScaleFactor();
            Log.d("Factor", String.valueOf(factor));


            float product = size*factor;
            Log.d("TextSize", String.valueOf(product));
            scaleGesture.setTextSize(TypedValue.COMPLEX_UNIT_PX, product);

            size = scaleGesture.getTextSize();
            Log.d("TextSizeEnd", String.valueOf(size));
            return true;
        }
    }
}

sukharta.xml文件

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">
<TextView
    android:id="@+id/textView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>
</ScrollView>
</LinearLayout>

缩放适用于没有ScrollViewTextView ,但是内容超出框架,我无法向下滚动以查看该内容。 但是,当我添加ScrollView ,我无法缩放。 请帮忙。

尝试此设置您的scrollview属性android:fillViewport="true"

<ScrollView
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:fillViewport="true">

 <LinearLayout
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:orientation="vertical">
    <TextView
       android:id="@+id/textView"
       android:layout_width="match_parent"
       android:layout_height="match_parent"/>
 </LinearLayout>

</ScrollView>

你可以试试:

<TextView
    android:id="@+id/textView"
    android:scrollbars="vertical"
    android:maxLines="LINES"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

textView.setMovementMethod(new ScrollingMovementMethod());

可能是NestedScrollView的作品,您可以尝试上面的代码。

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">

   <LinearLayout

            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

    <TextView
        android:id="@+id/textView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
    </LinearLayout>
</android.support.v4.widget.NestedScrollView>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM