亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

NestedScrollView 在以編程方式添加 TextView 時不滾動

NestedScrollView 在以編程方式添加 TextView 時不滾動

蝴蝶刀刀 2023-05-10 13:55:14
我在我的應用程序的一個屏幕上包括一個棋盤和棋子,我想在它下面添加一個可滾動的視圖,以在用戶移動時顯示移動符號。我可以將文本添加到視圖中,但無論我嘗試什么,視圖都不會滾動。我已經廣泛研究了其他用戶在這個問題上遇到的麻煩。我已經包括 fillViewport="true" 和 layout_height="wrap_content" 但這些解決方案都不適合我。我玩過 nestedscrollview 的邊距無濟于事,過去幾天我一直遇到這個問題,但仍然沒有弄清楚我做錯了什么。這是 xml 文件:<?xml version="1.0" encoding="utf-8"?><android.support.constraint.ConstraintLayout 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/chessBoardScreen"    android:layout_width="match_parent"    androi:layout_height="match_parent"    android:clickable="true"    android:focusable="true"    app:layout_behavior="@string/appbar_scrolling_view_behavior"    tools:context=".ChessBoardActivity"    tools:showIn="@layout/app_bar_chess_board">    <android.support.constraint.ConstraintLayout        android:id="@+id/cl_parent"        android:layout_width="wrap_content"        android:layout_height="350dp"        app:layout_constraintBottom_toTopOf="@+id/move_view"        app:layout_constraintEnd_toEndOf="parent"        app:layout_constraintStart_toStartOf="parent"        app:layout_constraintTop_toTopOf="parent">        <ImageView            android:id="@+id/board"            android:layout_width="wrap_content"            android:layout_height="329dp"            android:layout_marginTop="8dp"            app:layout_constraintEnd_toEndOf="parent"            app:layout_constraintStart_toStartOf="parent"            app:layout_constraintTop_toTopOf="parent"            app:srcCompat="@drawable/chess_board" />        </android.support.constraint.ConstraintLayout>    </android.support.constraint.ConstraintLayout>
查看完整描述

1 回答

?
瀟瀟雨雨

TA貢獻1833條經驗 獲得超4個贊

編輯:

我剛剛注意到代碼中的實際問題。您正在使用翻譯手動設置位置,這樣做不會更新父布局的高度,這就是滾動視圖不會滾動的原因。您應該使用 LinearLayout,這樣您就不必計算位置,如果有兩列,您可以使用 GridLayout。


舊答案:調用scrollView.invalidate()以便 scrollview 可以適應變化。如果它不起作用,那么invalidate()也調用 ConstraintLayout。如果還是不行,那就也打電話requestLayout()。


 ml.addView(tv);

 ml.invalidate();

 NestedScrollView scrollView = findViewById(R.id.move_view);

 scrollView.invalidate();

 scrollView.requestLayout();


查看完整回答
反對 回復 2023-05-10
  • 1 回答
  • 0 關注
  • 170 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號