簡體   English   中英

如何在 kotlin 中擴展 Fragment 的視圖范圍?

[英]How to expand the range of view for Fragment in kotlin?

下面代碼運行的視圖范圍很小。 目前,它僅在 Fragment 的最頂部運行。

以下是 setOnTouchListener 的代碼:

val view = inflater.inflate(R.layout.fragment_main, container, false)
view.setOnTouchListener(View.OnTouchListener { view, motionEvent ->
            if (motionEvent.action == MotionEvent.ACTION_UP){
                texteffectskip = true
            }
            return@OnTouchListener true
        })

活動_main.xml

<FrameLayout
        android:id="@+id/main_frame"
        android:layout_width="match_parent"
        android:layout_height="0dp"

片段.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".fragment_main"
    >

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintBottom_toTopOf="@+id/recyclerView"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_margin="20dp">

        <TextView
            android:id="@+id/txt_content"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text=""
            android:textSize="20sp"/>

    </ScrollView>

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="20dp"
        app:layout_constraintBottom_toBottomOf="parent" />
    
</androidx.constraintlayout.widget.ConstraintLayout>

我想在整個 Fragment 中運行。 我試圖調整布局的高度,但沒有幫助。

任何幫助表示贊賞!

目前,View 有 ScrollView 和 ReyclerView。 我想如果我按下 ScrollView,就會按下 View。 但事實並非如此。 所以我必須將一個 TouchListener 附加到另一個視圖。

var scroller = view.findViewById(R.id.scroll_content) as ScrollView
scroller.setOnTouchListener(View.OnTouchListener { view, motionEvent ->
    if (motionEvent.action == MotionEvent.ACTION_UP){
        texteffectskip = true
    }
    return@OnTouchListener true
})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM