我制作了 cardView 并實作了 onClickListener,我還創建了一個卡片導航到其中有一個 textView 的片段。

請問這是什么原因??
這是 .kt 檔案中的 onClickListener 代碼;
// ssJkRowling
val ssJoanneRowling : CardView = view.findViewById(R.id.ss_jk_rowling)
ssJoanneRowling.setOnClickListener {
val ssJoanneRowlingFragment = SsJoanneRowlingFragment()
val transaction: FragmentTransaction? = fragmentManager?.beginTransaction()
transaction?.replace(R.id.fl_fragment, ssJoanneRowlingFragment)
transaction?.commit()
}
這是 .xml 檔案中的 cardView;
<androidx.cardview.widget.CardView
android:id="@ id/ss_jk_rowling"
android:layout_width="250dp"
android:layout_height="320dp"
app:cardElevation="6dp"
app:cardCornerRadius="12dp"
android:layout_margin="30dp"
android:layout_rowWeight="1"
android:layout_columnWeight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="260dp"
android:src="@drawable/ss_jk_rowling"
android:scaleType="centerCrop"
android:contentDescription="@string/stories_imageview"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="55dp"
android:padding="15dp"
android:text="@string/Joanne_Rowling"
android:textSize="18sp" />
</LinearLayout>
</androidx.cardview.widget.CardView>
這里是 cardView 導航到的片段中的 textView 代碼;
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.Constraints 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=".SsJoanneRowlingFragment">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="15dp"
android:text="@string/Joanne_Rowling_story" />
</LinearLayout>
</ScrollView>
</androidx.constraintlayout.widget.Constraints>
這對您的幫助很大。
uj5u.com熱心網友回復:
您可以Constraints從目標的 xml 布局中洗掉并ScrollView用作父級,它應該可以作業:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent">
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical">
<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:padding="15dp"
android:text="@string/Joanne_Rowling_story" />
</LinearLayout>
</ScrollView>
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/401864.html
標籤:安卓 科特林 安卓布局 android-fragments 文本视图
上一篇:從同一個父類的另一個類訪問物件
下一篇:使用navArgs將Fragment轉換為DialogFragment,如何從Fragment類外部導航到DialogFragment
