【发布时间】:2021-04-08 02:21:32
【问题描述】:
我想显示 4 个 textViews 或只显示一个 editText,具体取决于我从后端收到的数据
以下是我的看法
<LinearLayout 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"
android:orientation="vertical">
<LinearLayout
android:id="@+id/groupOfFour"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/first"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<TextView
android:id="@+id/second"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<TextView
android:id="@+id/third"
android:layout_width="match_parent"
android:layout_height="match_parent"
t/>
<TextView
android:id="@+id/fourth"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
在我的片段中,我正在这样做
class MyFragment : Fragment(R.layout.my_fragment) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val backedData = getRemoteData()
if(backedData.hasFour()) {
editText.visibility = Visibility.GONE
// set the four text view
} else {
groupOfFour.visibility = Visibility.GONE
}
}
}
还有其他方法可以实现相同的行为吗?
【问题讨论】:
标签: android android-layout kotlin android-fragments textview